Codeforces Round 379 (Div. 2)
D
Anton and Chess
Codeforces
1700
原题
← CE →
翻译中…

Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on $8$ to $8$ board to too simple, he uses an infinite one instead.

翻译中…

The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.

翻译中…

Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.

翻译中…

Help Anton and write the program that for the given position determines whether the white king is in check.

翻译中…

Remainder, on how do chess pieces move:

翻译中…
  • Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
  • Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
  • Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 500 000$) — the number of black pieces.

翻译中…

The second line contains two integers $*x*_{0}$ and $*y*_{0}$ ($- 10^{9} ≤ *x*_{0}, *y*_{0} ≤ 10^{9}$) — coordinates of the white king.

翻译中…

Then follow $*n*$ lines, each of them contains a character and two integers $*x*_{*i*}$ and $*y*_{*i*}$ ($- 10^{9} ≤ *x*_{*i*}, *y*_{*i*} ≤ 10^{9}$) — type of the $*i*$-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.

翻译中…

Output

翻译中…

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.

翻译中…

Note

翻译中…

Picture for the first sample:

翻译中…

image

翻译中…

White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "

翻译中…

YES

翻译中…

".

翻译中…

Picture for the second sample:

翻译中…

image

翻译中…

Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "

翻译中…

NO

翻译中…

".

翻译中…

样例

Input #1
2
4 2
R 1 1
B 1 5
Output #1
YES
InputCopy OutputCopy
Input #2
2
4 2
R 3 3
B 1 5
Output #2
NO
InputCopy OutputCopy
题目信息
题号
734D
时间限制
4 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。