Combining Rectangles
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
On a plane, you are given N rectangles. Each rectangle has vertices at points with integer coordinates, and its sides are parallel to the coordinate axes.
Your task is to determine the total area covered by the union of these rectangles.
Input
The first line of the input contains the integer N (0 ≤ N ≤ 1500). Each of the following N lines contains four integers: x_1, y_1, x_2, y_2. These represent the coordinates of the bottom-left corner (x_1, y_1) and the top-right corner (x_2, y_2) of a rectangle (0 ≤ x_1 ≤ x_2 ≤ 10^9, 0 ≤ y_1 ≤ y_2 ≤ 10^9). Note that rectangles may degenerate into line segments or points.
Output
Output a single number representing the total area of the union of the rectangles.
Examples
Input #1
Answer #1
Submissions 571
Acceptance rate 28%