6907.Area of Rectangles

Time Limit: 1s Memory Limit: 512MB

Given $n$ rectangles, your task is to determine the total area of their union.

Input Format(From the terminal/stdin)

The first line has an integer $n$ : the number of rectangles.

After that, there are $n$ lines describing the rectangles. Each line has four integers $x_1$ , $y_1$ , $x_2$ and $y_2$ : a rectangle begins at point $(x_1,y_1)$ and ends at point $(x_2,y_2)$ .

  • $1 \le n \le 10^5$
  • $-10^6 \le x_1 < x_2 \le 10^6$
  • $-10^6 \le y_1 < y_2 \le 10^6$

Output Format(To the terminal/stdout)

Print the total area covered by the rectangles.

Sample Input

Copy
3
1 3 4 5
3 1 7 4
5 3 8 6
 \n
 · · · \n
 · · · \n
 · · · \n

Sample Output

Copy
24
  \n
Source: CSES, Geometry, 1741

Submit

请先 登录

© 2025 FAQs