#P8648. Archaeological Robots: Union Area Calculation

    ID: 21814 Type: Default 1000ms 256MiB

Archaeological Robots: Union Area Calculation

Archaeological Robots: Union Area Calculation

A team of archaeological robots on planet X have reported several rectangular regions (given as two diagonal points) where they plan to perform excavation. In order to mark these regions clearly, the headquarters requires all reported regions to be painted yellow. Your task is to calculate the total area that is covered by these rectangles, knowing that areas may overlap.

The rectangles are specified in the format \( (x_1, y_1, x_2, y_2) \), which represents the coordinates of two opposite corners. The total area to be painted is the union of all these rectangular regions.

Input Format: The first line contains an integer \( N \) representing the number of rectangles. Each of the next \( N \) lines contains four integers \( x_1, y_1, x_2, y_2 \) separated by spaces.

Output Format: Output a single integer denoting the total area covered by these rectangles. (Note that overlapping regions should only be counted once.)

inputFormat

The input begins with an integer \( N \). This is followed by \( N \) lines, each containing four space-separated integers \( x_1, y_1, x_2, y_2 \), representing the coordinates of two opposite corners of a rectangle.

outputFormat

Output a single integer representing the total area covered by the union of the given rectangles.

sample

1
0 0 1 1
1