Area of Rectangles
From CSES. Union area with sweep line. Solve the geometry problem "Area of Rectangles".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
Sweep line over x: collect all distinct x-coordinates from rectangle left and right edges, sort them. The union area between consecutive x's is Δx times the total y-length covered by active rectangles.
At each event x, toggle each rectangle's y-interval [y1, y2] in/out of the active set. Maintain the total covered y-length by tracking a coverage count over compressed y-intervals.
Compress both x and y coordinates for performance. Use a count array over the compressed y-segments: increment when a rectangle starts, decrement when it ends. Update total_y_covered only when a segment's count transitions between 0 and 1 or 1 and 0.
Area of Rectangles
**From CSES.** Union area with sweep line. Solve the geometry problem "Area of Rectangles".