Carpets
InterviewTime limit1sMemory limit1024 MB
Given up to three axis-aligned rectangles, find the total area of their union.
- Level
Easy3 of 10
- Topics
- Geometry, Implementation, Math, Brute force
- Solved
- No attempts yet
Problem
The grandest hall of Prince Ville's new castle has a rectangular floor. Its walls run North-South and East-West. Ville's advisors have proposed covering parts of the floor with carpets and have even suggested a specific arrangement.
Caring mostly about the size of the deal, Ville wants to know the total area of the floor covered by the carpets in this arrangement. Where carpets overlap, the shared region is counted only once.
Input
The first line contains three space-separated integers , , and : the number of carpets (), the distance from the East wall to the West wall (), and the distance from the North wall to the South wall ().
Each of the next lines contains four space-separated integers , , , and describing one carpet. The carpet's edges are parallel to the walls, and , , , and give the distance of the carpet's North, South, East, and West edge from the corresponding wall, respectively. Carpets may overlap partially or fully. All distances are in metres.
Output
Print a single integer : the total area of the floor covered by carpets, in square metres.