#P3079. Counting Outer Enclosures
Counting Outer Enclosures
Counting Outer Enclosures
After several harsh winters, Farmer John has decided it is time to repaint his farm. The farm consists of n fenced enclosures ($1 \leq n \leq 50000$), each described by a rectangle in the 2D plane with sides parallel to the x‐ and y-axes. Even though enclosures may be nested (one completely contained within another), no two fences intersect (i.e. they do not even touch). Thus, if two enclosures cover overlapping regions of the plane, then one must be entirely contained in the other.
Farmer John reasons that an enclosure which is contained within another will not be visible from the outside. Being rather lazy, he only wants to repaint the enclosures that are actually exposed. Please help him determine the total number of enclosures he needs to paint – that is, the number of enclosures that are not contained in any other enclosure.
Mathematically, each enclosure is given by its coordinates as a rectangle $(x_1, y_1, x_2, y_2)$ with the conditions that $x_1 < x_2$ and $y_1 < y_2$. An enclosure A is contained within an enclosure B if and only if \[ B.x_1 < A.x_1,\quad B.y_1 A.x_2,\quad B.y_2 > A.y_2. \]
inputFormat
The first line contains a single integer n, the number of enclosures. The following n lines each contain four space-separated integers x1 y1 x2 y2, representing an enclosure.
outputFormat
Output a single integer: the number of outer enclosures (the ones not contained in any other enclosure).
sample
3
0 0 10 10
2 2 5 5
20 20 30 30
2