Venue Rental (Small)
InterviewTime limit2sMemory limit256 MB
Given up to 100 axis-aligned rectangles, find the area of the union of all rectangles.
- Level
Medium4 of 10
- Topics
- Array, Implementation, Simulation, Geometry
- Solved
- No attempts yet
Problem
Sanghyun is about to leave for military service and wants to throw a farewell party. He rents a venue for it, and the rental company is unusual because only former programmers work there.
Once Sanghyun picks the place he wants, the company builds rectangles that cover that place completely. It then tells him the number of rectangles and, for each rectangle, the coordinates of its bottom left corner and its top right corner. The rectangles may overlap partially or completely. Every rectangle has sides parallel to the coordinate axes.
Write a program that computes the area of the venue Sanghyun rented, that is, the area of the region covered by at least one of the rectangles.
Input
The first line contains the number of rectangles ().
Each of the next lines contains four integers , , , (, ) separated by spaces. The bottom left corner of that rectangle is and the top right corner is .
Output
Print the area of the venue Sanghyun rented on the first line. The area is always an integer, so print it without a decimal point.