Area of Rectangles

0

0 votes
Geometry, Mathematics, Line Sweep Technique, Easy-Medium
Problem

Given a set of N axis aligned rectangles, you need to find the area of their union. Each rectangle is represented by two points, one lower-left point and one upper-right point. The coordinates are all integers.

Input:
First line consists of N denoting the number of rectangles.
Following N lines consist of x1,y1,x2,y2 each where (x1,y1) represents the lower-left point and (x2,y2) represents the upper-right point of i th rectangle.

Output:
Print the area of the union of the rectangles.

Constraints:
1N104
1x1 < x2105
1y1 < y2105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The area of the union is 9.

Editor Image

?