#P16403. [ECUSTPC 2026 Spring] 净化行动 2

    ID: 18417 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>Special Judge2026高校校赛

[ECUSTPC 2026 Spring] 净化行动 2

Problem Description

Maddy is still wiping out Baddy’s evil army.

The game is played on an infinite Chinese chess board. The board consists of countless horizontal and vertical lines. Each intersection can hold one piece. For convenience, we model it as a 2D Cartesian coordinate system, and use 2D Cartesian coordinates to represent the positions of pieces.

Baddy controls nn black pawn pieces and one black general piece. These pieces stay fixed at their initial positions throughout the game and will not move. The black pawns are placed at intersections (x1,y1),(x2,y2),…,(xn,yn)(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n), and the black general is at (xK,yK)(x_K, y_K).

Now Maddy controls one red cannon piece. She can place the red cannon at any empty position (intersection) on the board. The red cannon follows the movement rules of Chinese chess, specifically:

  • Move: move any number of squares along its current horizontal line or vertical line. In one move it can only choose horizontal or vertical, not both. It cannot cross over other pieces on the same line, and it also cannot capture during a move.
  • Capture: choose an enemy piece on the same line (horizontal or vertical) as the target, but there must be exactly one piece in between (any piece). After capturing, the cannon moves to the position of the captured enemy piece, and the captured piece is removed from the board.

After placing the red cannon, Maddy may keep moving it any number of times according to the rules above.

Maddy now wants to know whether there exists a valid placement plan and a sequence of moves for the red cannon that can eventually capture the black general. Please help her.

Input Format

The first line contains an integer T (1≤T≤105)T\ (1 \le T \le 10^5), the number of testdata.

For each testdata, the first line contains 33 integers n,xKn, x_K and $y_K\ (0 \le n \le 10^5, -10^9 \le x_K, y_K \le 10^9)$, representing the number of black pawns and the coordinates of the black general.

Then follow nn lines. The ii-th line contains two integers xi,yi(−109≤xi,yi≤109)x_i, y_i (-10^9 \le x_i, y_i \le 10^9), representing the position of the ii-th black pawn.

It is guaranteed that ∑n≤3×105\sum n \le 3 \times 10^5 over all testdata. It is guaranteed that within each testdata, all black pawns have pairwise distinct positions, and the black general’s position is different from every black pawn’s position.

Output Format

For each testdata, if there exists a valid placement plan and a sequence of moves for the red cannon that can capture the black general, output one line with the string YES; otherwise output one line with the string NO.

Note that the judge is case-insensitive for YES and NO. In other words, when the answer is positive, outputs like yes, YES, Yes, YeS, etc. are all accepted.

3
0 0 0
1 1 1
0 1
4 1 0
0 1
2 1
1 1
1 2
NO
YES
NO

Hint

Explanation for Sample 1

The figure below shows the positions of Black’s pieces in the 22-nd testdata and one possible placement position for Maddy’s red cannon, namely at (−2,−1)(-2, -1). Then it can capture the black general directly.

:::align{center}

Figure 1: The 22-nd testdata :::

The figure below shows the positions of Black’s pieces in the 33-rd testdata.

:::align{center}

Figure 2: The 33-rd testdata :::

Please note that for convenience of demonstration, the sample figures draw the board boundary, but in fact the statement has already pointed out that the board is infinite.

Translated by ChatGPT 5