#P5998. [PA 2014] Plemiona
[PA 2014] Plemiona
Description
In ancient times, there were tribes spread across the territory of the Giri Kingdom. After setting up a 2D Cartesian coordinate system, each tribe is represented by an axis-aligned rectangle. Some lands may belong to multiple tribes at the same time. As time goes by, tribes may merge. Specifically, if the intersection area of two tribes is strictly greater than zero, they merge into a new tribe. The shape of the new tribe is the smallest axis-aligned rectangle that contains both original tribes.
Millions of years later, the tribes finally reach a stable state (no two tribes can be merged anymore), but Giri has already grown old. He wants to know how many tribes remain in the end, and the position of each tribe. Can you help him finish this task?
Input Format
The first line contains an integer , representing the number of tribes in ancient times.
The next lines each contain four integers , representing the coordinates of a tribe.
Output Format
The first line outputs an integer , representing the number of tribes remaining after reaching stability.
The next lines each contain four integers , representing the coordinates of a tribe.
Please output them in increasing lexicographical order (compare first; if is equal, compare , and so on).
5
7 8 1 4
1 5 2 3
4 5 2 7
2 3 5 9
4 6 8 9
2
1 6 2 9
7 8 1 4
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号