#P15214. [NWERC 2025] Illuminated Stalls

    ID: 15191 远端评测题 8000ms 2048MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心计算几何2025枚举哈希 hashingICPC

[NWERC 2025] Illuminated Stalls

Description

Year after year, you have strolled through the Christmas market, catching up with old friends over mulled wine. Lately the prices have been absurd, and just a few evenings leave you in the financial ruin. This year, you decided to turn things around and open a stall selling mulled wine. But competition is fierce, and it turns out that yet another absurdly overpriced stall is far less profitable than you hoped.

To stand out, you created a difficult puzzle. If a customer solves it, they can drink as much mulled wine as they want for free. Naive customers are often willing to pay more than usual.

This puzzle consists of nn line-shaped neon light tubes hanging on the wall. They are oriented either horizontally or vertically. No two horizontal lights overlap or touch and no two vertical lights overlap or touch, but a vertical light can intersect or touch a horizontal light. The player is allowed to rotate and/or move at most one light tube in any way they like. The goal is to have at least one illuminated neon light square. All four sides of this square have to be fully covered by neon lights, but the lights can be longer than the sides of the square.

Lights are allowed to lie in the interior of the square or intersect its sides. The light that is moved is allowed to be placed such that it touches, partially overlaps, or fully overlaps other collinear lights.

You want to make this puzzle as hard as possible, but if there is no valid solution, you will get into trouble with the German lawmakers, as regulations are very strict. Given a puzzle, find out whether there is a way to make a square by moving and/or rotating at most one light.

Input Format

The input consists of:

  • One line with an integer tt (1t200001 \le t \le 20000), the number of test cases.
  • For each test case, the input consists of:
    • One line with an integer nn (4n21054 \le n \le 2 \cdot 10^5), the number of neon light tubes.
    • nn lines, each with four integers x1,y1,x2x_1, y_1, x_2, and y2y_2 ($0 \le x_1, y_1, x_2, y_2 \le 10^9, x_1 \le x_2, y_1 \le y_2$, and either x1=x2x_1 = x_2 or y1=y2y_1 = y_2, but not both), where (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) are the endpoints of a light tube. The total number of light tubes over all test cases is at most 21052 \cdot 10^5.

All light tubes are either vertical or horizontal. For every test case, the initial configuration has no two overlapping or touching horizontal lights, and also has no two overlapping or touching vertical lights. Note that horizontal lights can intersect and touch vertical lights.

Output Format

For each test case, output "yes" if there is a way to make a square by moving and/or rotating at most one light, otherwise output "no".

5
4
0 0 0 1
0 1 1 1
1 0 1 1
0 0 1 0
4
0 0 0 4
0 4 4 4
4 0 4 4
10 10 10 14
5
0 0 0 4
0 4 4 4
3 1 4 1
4 0 4 4
10 10 10 13
5
0 0 0 4
0 4 4 4
4 0 4 4
3 0 4 0
10 10 10 13
9
1 3 6 3
2 1 2 8
2 7 8 7
4 6 6 6
6 7 6 8
5 5 7 5
6 2 6 4
7 3 11 3
9 1 9 5
yes
yes
no
yes
yes

Hint

Figure I.1\text{I.1}: On the left, the initial configuration of lights of the fifth test case of Sample Input 11 is shown. On the right, the purple neon light was rotated and moved to make a 4×44 \times 4 square.