문제1639--Mars Map

1639: Mars Map

실행시간 제한: 10 Sec  메모리사용 제한: 128 MB
제출: 182  통과: 65
[제출] [채점기록] [묻고답하기]

문제 설명

In the year 2051, several Mars expeditions have explored different areas of the red planet and produced maps of these areas. Now, the BaSA (Baltic Space Agency) has an ambitious plan: they would like to produce a map of the whole planet. In order to calculate the necessary effort, they need to know the total size of the area for which maps already exist. It is your task to write a program that calculates this area.

입력 설명

The input contains several test cases. The first line of whole input will contain a single integer T, the number of test cases.

Each test case starts with a line containing a single integer N (1 ≤ N ≤ 8000), the number of available maps. Each of the following N lines describes a map. Each of these lines contains four integers x1, y1, x2 and y2 (0 ≤ x1 < x2 ≤ 30 000, 0 ≤ y1 < y2 ≤ 30 000). The values (x1,y1) and (x2,y2) are the coordinates of, respectively, the bottom-left and the top-right corner of the mapped area. Each map has rectangular shape, and its sides are parallel to the x- and y-axis of the coordinate system.

출력 설명

﻿For each test case, write a single which contains one integer A, the total explored area (i.e. the area of the union of all rectangles).

입력 예시 Copy

2
2
10 10 20 20
15 15 25 30
1
0 0 1 1

출력 예시 Copy

225
1

도움

Even though there is an O(N lgN) algorithm, but a O(N2) solution will be enough for this problem.