#P6081. Expandable Barns
Expandable Barns
Expandable Barns
Farmer John has N rectangular barns (1 ≤ N ≤ 25000) whose walls are parallel to the coordinate axes and all coordinates lie in the range \([0,10^6]\). It is guaranteed that any two barns do not overlap, although they may share walls.
Due to the increasing number of cows, FJ plans to expand some barns. A barn is expandable if and only if none of its walls share any common part with the walls of any other barn. In addition, if two barns share a common corner (i.e. a point), then both barns cannot be expanded.
More formally, consider a barn with bottom‐left corner \((x_1,y_1)\) and top‐right corner \((x_2,y_2)\). Two barns are adjacent if one of the following holds:
- The left wall of one barn is exactly the same as the right wall of another barn, and their vertical intervals \([y_1,y_2]\) intersect. The intersection is considered a common wall if the length of the overlapping interval is positive, or a common corner if the overlap is exactly zero.
- The bottom wall of one barn is exactly the same as the top wall of another barn, and their horizontal intervals \([x_1,x_2]\) intersect. Again, an overlap of positive length indicates a common wall, while an overlap of zero indicates a common corner.
Your task is to count how many barns are expandable.
inputFormat
The first line contains an integer N.
Each of the next N lines contains four integers: x1, y1, x2, y2 (with x1 < x2 and y1 < y2) representing the coordinates of a barn.
outputFormat
Output a single integer: the number of barns that are expandable.
sample
4
0 0 1 1
1 0 2 1
0 1 1 2
1 1 2 2
0