Signal Flood
The central district of Neon City is covered by a swarm of emergency transmitters. Each transmitter floods an axis-aligned rectangular region of the ground with radio noise.
Your repair drone can only land in places receiving exactly K simultaneous broadcasts. After all N transmitters are active, determine the total area where the signal strength is exactly K.
Model the district as the 2D x-y plane. Each transmitter is described by the coordinates of the lower-left and upper-right corners of its rectangular coverage zone.
Input
The first line contains two integers N and K.
Each of the next N lines contains four integers x1,y1,x2,y2, describing a rectangle with lower-left corner (x1,y1) and upper-right corner (x2,y2).
Output
Output a single integer: the area covered by exactly K transmitters.
Constraints
- 1≤K≤N≤105
- 0≤x1<x2≤1000
- 0≤y1<y2≤1000
Example 1
3 2
1 1 5 5
4 4 7 6
3 3 8 7
8
Explanation
Exactly eight unit squares are covered by two transmitters.
Example 2
4 1
0 0 2 3
2 0 4 3
1 1 3 2
0 3 4 4
14
Explanation
The third rectangle overlaps one unit square from each of the first two rectangles. Those two overlapped squares have coverage 2, so the remaining 14 units of area have coverage exactly 1.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.