{"problem":{"name":"D. Anton and Chess","description":{"content":"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","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":4000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF734D"},"statements":[{"statement_type":"Markdown","content":"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.\n\nThe 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.\n\nConsider 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.\n\nHelp Anton and write the program that for the given position determines whether the white king is in check.\n\nRemainder, on how do chess pieces move:\n\n*   Bishop moves any number of cells diagonally, but it can't \"leap\" over the occupied cells.\n*   Rook moves any number of cells horizontally or vertically, but it also can't \"leap\" over the occupied cells.\n*   Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't \"leap\".\n\n## Input\n\nThe first line of the input contains a single integer _n_ (1 ≤ _n_ ≤ 500 000) — the number of black pieces.\n\nThe second line contains two integers _x_0 and _y_0 ( - 109 ≤ _x_0, _y_0 ≤ 109) — coordinates of the white king.\n\nThen follow _n_ lines, each of them contains a character and two integers _x__i_ and _y__i_ ( - 109 ≤ _x__i_, _y__i_ ≤ 109) — 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.\n\n## Output\n\nThe only line of the output should contains \"_YES_\" (without quotes) if the white king is in check and \"_NO_\" (without quotes) otherwise.\n\n[samples]\n\n## Note\n\nPicture for the first sample:\n\n<center>![image](https://espresso.codeforces.com/f93d849830ccab945077eb5a518b26b0b4f419e0.png)</center>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:\n\n<center>![image](https://espresso.codeforces.com/6d8e343cc54e912524bf3214dd50aacfbf85ede2.png)</center>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_\".","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Anton 喜欢下棋，也喜欢编程。因此，他决定编写一个下棋程序。然而，他认为在 #cf_span[8] 到 #cf_span[8] 的棋盘上游戏过于简单，于是改用无限大的棋盘。\n\n他面临的第一个任务是判断国王是否处于被将军状态。Anton 不知道如何实现这一点，因此他请求你帮忙。\n\n假设一个无限大的棋盘上有一个白方国王和若干黑方棋子。目前只支持车、象和后，其他棋子尚未实现。如果至少有一个黑方棋子能在一步内移动到国王所在的格子，则称白方国王处于被将军状态。\n\n请帮助 Anton 编写一个程序，根据给定的棋盘局面判断白方国王是否处于被将军状态。\n\n回忆一下国际象棋棋子的走法：\n\n输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 500 000]) —— 黑方棋子的数量。\n\n第二行包含两个整数 #cf_span[x0] 和 #cf_span[y0] (#cf_span[ - 109 ≤ x0, y0 ≤ 109]) —— 白方国王的坐标。\n\n接下来 #cf_span[n] 行，每行包含一个字符和两个整数 #cf_span[xi] 和 #cf_span[yi] (#cf_span[ - 109 ≤ xi, yi ≤ 109]) —— 第 #cf_span[i] 个棋子的类型及其位置。字符 '_B_' 表示象，'_R_' 表示车，'_Q_' 表示后。保证没有两个棋子占据同一位置。\n\n输出仅一行，如果白方国王处于被将军状态，则输出 \"_YES_\"（不含引号），否则输出 \"_NO_\"（不含引号）。\n\n第一组样例的图示：\n\n第二组样例的图示：\n\n## Input\n\n输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 500 000]) —— 黑方棋子的数量。第二行包含两个整数 #cf_span[x0] 和 #cf_span[y0] (#cf_span[ - 109 ≤ x0, y0 ≤ 109]) —— 白方国王的坐标。接下来 #cf_span[n] 行，每行包含一个字符和两个整数 #cf_span[xi] 和 #cf_span[yi] (#cf_span[ - 109 ≤ xi, yi ≤ 109]) —— 第 #cf_span[i] 个棋子的类型及其位置。字符 '_B_' 表示象，'_R_' 表示车，'_Q_' 表示后。保证没有两个棋子占据同一位置。\n\n## Output\n\n输出仅一行，如果白方国王处于被将军状态，则输出 \"_YES_\"（不含引号），否则输出 \"_NO_\"（不含引号）。\n\n[samples]\n\n## Note\n\n第一组样例的图示：\n\n白方国王处于被将军状态，因为黑方象可以在一步内移动到国王所在的格子。答案是 \"_YES_\"。\n\n第二组样例的图示：\n\n此处，象无法移动到国王所在的格子，因为其路径被车阻挡，而象不能\"跳过\"其他棋子。车也无法移动到白方国王处，因为它不能沿对角线移动。因此，国王未被将军，答案是 \"_NO_\"。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of black pieces.  \nLet $ K = (x_0, y_0) \\in \\mathbb{Z}^2 $ be the position of the white king.  \nLet $ P = \\{ (t_i, x_i, y_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of black pieces, where $ t_i \\in \\{ \\text{B}, \\text{R}, \\text{Q} \\} $ is the type of the $ i $-th piece, and $ (x_i, y_i) \\in \\mathbb{Z}^2 $ is its position.\n\n**Constraints**  \n1. $ 1 \\le n \\le 500{,}000 $  \n2. $ -10^9 \\le x_0, y_0, x_i, y_i \\le 10^9 $ for all $ i $  \n3. All piece positions are distinct.\n\n**Objective**  \nDetermine whether there exists at least one piece $ (t_i, x_i, y_i) \\in P $ such that:  \n- If $ t_i = \\text{R} $: $ x_i = x_0 $ or $ y_i = y_0 $, and no other piece lies on the line segment between $ (x_i, y_i) $ and $ (x_0, y_0) $.  \n- If $ t_i = \\text{B} $: $ |x_i - x_0| = |y_i - y_0| \\ne 0 $, and no other piece lies on the diagonal segment between $ (x_i, y_i) $ and $ (x_0, y_0) $.  \n- If $ t_i = \\text{Q} $: either $ x_i = x_0 $, or $ y_i = y_0 $, or $ |x_i - x_0| = |y_i - y_0| \\ne 0 $, and no other piece lies on the line segment between $ (x_i, y_i) $ and $ (x_0, y_0) $.  \n\nOutput \"YES\" if such a piece exists; otherwise, output \"NO\".","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF734D","tags":["implementation"],"sample_group":[["2\n4 2\nR 1 1\nB 1 5","YES"],["2\n4 2\nR 3 3\nB 1 5","NO"]],"created_at":"2026-03-03 11:00:39"}}