#P10821. Determining Attacked Rooks on an Infinite Chessboard

    ID: 12864 Type: Default 1000ms 256MiB

Determining Attacked Rooks on an Infinite Chessboard

Determining Attacked Rooks on an Infinite Chessboard

Prof. Pang and Prof. Shou are playing chess with rooks on an infinite chessboard which can be viewed as a 2D plane. Prof. Pang placed \(n_1\) rooks and Prof. Shou placed \(n_2\) rooks. Each rook is represented as a point with integer coordinates.

A rook is attacked by another rook if all of the following conditions hold:

  • They belong to different players.
  • They share either the same \(x\)-coordinate or the same \(y\)-coordinate.
  • There is no other rook on the straight line segment between them.

Your task is to determine for each rook whether it is attacked by at least one opponent rook. The output should have two lines: the first line for Prof. Pang's rooks and the second line for Prof. Shou's rooks. For each rook, output "YES" if it is attacked and "NO" otherwise, in the same order as input.

Note: For rooks sharing a row (or column), the attacking condition holds between two rooks if they are consecutive when sorted by their \(x\) (or \(y\)) coordinate. Only immediate neighbors on a row/column (with no rook in between) can attack each other.

inputFormat

The first line contains two integers \(n_1\) and \(n_2\) representing the number of rooks placed by Prof. Pang and Prof. Shou respectively. The next \(n_1\) lines each contain two integers \(x\) and \(y\) representing the coordinates of Prof. Pang's rooks. The following \(n_2\) lines each contain two integers \(x\) and \(y\) for Prof. Shou's rooks.

 n1 n2
 x1 y1
 x2 y2
 ...
 xn1 yn1
 x1 y1
 x2 y2
 ...
 xn2 yn2

outputFormat

Output two lines. The first line contains \(n_1\) space‐separated strings for Prof. Pang's rooks, and the second line contains \(n_2\) space‐separated strings for Prof. Shou's rooks. For each rook, output "YES" if it is attacked; otherwise, output "NO".

sample

2 2
0 0
1 0
0 1
1 1
YES YES

YES YES

</p>