#P11115. [ROI 2024] 白菜 (Day 1)
[ROI 2024] 白菜 (Day 1)
Background
Translated from ROI 2024 D1T4.
Ramazan decided to start an important business—growing cabbages. The field for growing cabbages is an infinite grid. Each grid cell can contain one cabbage. Ramazan only planted cabbages on part of the field. He plans to use several rectangular areas, and these rectangles may intersect. If a grid cell lies inside at least one rectangle, then this cell is considered planted with cabbages.
More precisely, Ramazan chose rectangles with coordinates (where , , ). If there exists at least one rectangle () such that and , then the grid cell is considered planted with cabbages.

Ramazan used to be a programmer (and also a prize winner), so he decided to use AI robots to periodically maintain the planting. One robot can serve any horizontal segment $(x_{\text{robot}_1}, x_{\text{robot}_2}, y_{\text{robot}})$, that is, all grid cells such that and .
Importantly, a robot can move only inside the planted area. He understands that, to minimize the number of robots, he needs to use horizontal segments that cannot be extended further. Ramazan will use a robot to work on the segment $(x_{\text{robot}_1}, x_{\text{robot}_2}, y_{\text{robot}})$ if the following conditions hold:
- All grid cells such that and belong to the planted area.
- The grid cell does not belong to the planted area.
- The grid cell does not belong to the planted area.
Problem Description
You need to collect statistics about how robots work on the planted area. If there exists a robot that works exactly on the grid segment , we say that the pair is served on row . More precisely, you need to:
- Find all pairs that are served on some row.
- For each such pair , find the number of rows on which it is served.
- For each such pair , find the maximum number of consecutive rows on which it is served. In other words, find the maximum value such that there exists a consecutive row interval (where ) such that on every row , the pair is served.
Input Format
The input contains multiple test cases. The first line contains an integer (), the number of test cases.
The first line of each test case contains an integer (), the number of rectangles.
The next lines each contain four integers , , , (, ), describing one rectangle.
Let be the sum of over all test cases. It is guaranteed that .
Output Format
For each test case, first output an integer (), the number of pairs that are served on some row. Then output lines, each containing four integers , , , (, ). Here, is the number of rows on which this pair is served, and is the maximum number of consecutive rows on which it is served.
Each pair must be different. Every pair that is served on some row must be output exactly once. The output order can be arbitrary.
4
2
2 2 3 3
3 3 4 4
2
2 1 2 3
1 2 3 2
4
2 2 4 5
3 4 9 7
2 9 9 10
7 1 9 7
7
2 1 2 9
5 1 6 8
4 5 7 6
1 8 4 10
1 6 3 6
1 2 7 3
4 1 7 1
3
2 3 1 1
2 4 1 1
3 4 1 1
2
1 3 1 1
2 2 2 1
4
2 4 2 2
2 9 4 2
3 9 2 2
7 9 3 3
6
1 4 2 2
1 6 1 1
1 7 3 2
2 2 4 2
4 7 2 1
5 6 2 1
Hint

In the first test case, robots serve the following segments: , , and . Therefore, the pairs , , and are served on some row, and each pair is served on only one row.
In the second test case, robots serve the following segments: , , and . Therefore, the pairs and are served on some row. The pair is served on rows and , while the pair is served on row .
Below are the pictures for the third and fourth test cases.

- If your program finds the wrong set of pairs that are served on some row, the test will receive zero points.
- If your program:
- Can correctly find this set, but not all are correct, the test will receive of the points.
- Can correctly find this set and all , but not all are correct, the test will receive of the points.
- Can correctly find this set, all , and all , the test will receive of the points.
Please note that if you want to get partial points, you still need to output some and values for each pair , but they do not have to all be correct.
Translated by ChatGPT 5