#P5490. 【模板】扫描线 & 矩形面积并

【模板】扫描线 & 矩形面积并

Problem Description

Find the union area of nn rectangles whose sides are parallel to the coordinate axes.

Input Format

The first line contains a positive integer nn.

The next nn lines each contain four non-negative integers x1,y1,x2,y2x_1, y_1, x_2, y_2, indicating that the four vertices of a rectangle are (x1,y1)(x_1, y_1), (x1,y2)(x_1, y_2), (x2,y2)(x_2, y_2), (x2,y1)(x_2, y_1).

Output Format

Output one positive integer in a single line, representing the total area covered by the union of the nn rectangles.

2
100 100 200 200
150 150 250 255

18000

Hint

For 20%20\% of the testdata, 1n10001 \le n \le 1000.
For 100%100\% of the testdata, 1n1051 \le n \le {10}^5, 0x1<x21090 \le x_1 < x_2 \le {10}^9, 0y1<y21090 \le y_1 < y_2 \le {10}^9.

Updated on 4.10 by Dengduck (kouhu) & yummy (implementation): one more test case was added.

Translated by ChatGPT 5