Radar Scanner
Time limit2sMemory limit512 MB
Given n axis-aligned rectangles, count triples whose common intersection is nonempty.
- Level
Medium7 of 10
- Topics
- Geometry, Intervals, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
There are n rectangular radar scanners on the plane. Their sides are all parallel to the coordinate axes. Each scanner covers some grid squares on the plane. The i-th scanner covers all squares satisfying and .
Today, the radar system is facing a critical low-power problem. To reduce coverage, you must choose exactly three scanners, and there must be at least one square covered by all three chosen scanners.
Find the number of tuples such that and there exists a square covered by all of scanners i, j, and k.
Input
The first line of the input contains an integer T (1 ≤ T ≤ 10), the number of test cases.
Each test case starts with a line containing an integer n (3 ≤ n ≤ 100 000), the number of radar scanners.
Each of the next n lines contains four integers , , , and (1 ≤ ≤ ≤ 1000, 1 ≤ ≤ ≤ 1000), describing the i-th radar scanner.
Output
For each test case, print a single line containing a single integer: the number of possible tuples.