Codeforces Round 1082 (Div. 2)
G1
Monotone Monochrome Matrices (Easy Version)
Codeforces
2500
原题
← FG2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, the constraints on $n$ and $q$ are smaller. You can hack only if you solved all versions of this problem.

翻译中…

A monochrome matrix of size $n \times n$ is a matrix of $n$ rows and $n$ columns, where each cell is colored either black or white. Let the color of cell $(r,c)$ in a monochrome matrix $C$ be denoted as $C[r,c]$.

翻译中…

Let's call such a matrix $C$ monotone if it satisfies the following condition:

翻译中…
  • There exist no two rows $1 \le i \lt j \le n$ and two columns $1 \le k \lt l \le n$ that satisfy the following three conditions:
  • $C[i,k]=C[j,l]$;
    • $C[j,k]=C[i,l]$;
    • $C[i,k] \neq C[j,k]$.
翻译中…

There is a monochrome matrix $M$ of size $n \times n$, where all cells are initially white. Please solve $q$ queries of the following kind:

翻译中…
  • $r\;c$: Change the color of the cell $(r,c)$ in $M$ to black. Then, determine if $M$ is monotone or not.
翻译中…

For each query, it is guaranteed that the color of the cell $(r,c)$ was white before the query.

翻译中…

Do note that the updates are persistent. In other words, the change in color from one query affects the later queries as well.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $q$ ($2 \le n \le 25\,000$, $1 \le q \le \min(n^2,200\,000)$).

翻译中…

Each of the $q$ following lines contains two integers $r_i$, $c_i$ denoting the $i$-th query ($1 \le r_i,c_i \le n$).

翻译中…

For each query, it is guaranteed that the color of the cell $(r,c)$ was white before the query.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $25\,000$.

翻译中…

It is guaranteed that the sum of $q$ over all test cases does not exceed $200\,000$.

翻译中…

Output

翻译中…

For each query, output "YES" or "NO" on a separate line based on the answer of the query.

翻译中…

You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.

翻译中…

Note

翻译中…

In the first test case, $M$ has size $3 \times 3$. The states of $M$ after each query are as shown below.

翻译中…

$$\quad\, \begin{bmatrix} \square & \square & \square\\ \square & \blacksquare & \square\\ \square & \square & \square \end{bmatrix} \to \begin{bmatrix} \square & \square & \square\\ \square & \color{red}{\blacksquare} & \color{red}{\square}\\ \square & \color{red}{\square} & \color{red}{\blacksquare} \end{bmatrix} \to \begin{bmatrix} \square & \square & \square\\ \square & \blacksquare & \blacksquare\\ \square & \square & \blacksquare \end{bmatrix} \\\to \begin{bmatrix} \square & \square & \square\\ \color{red}{\square} & \color{red}{\blacksquare} & \blacksquare\\ \color{red}{\blacksquare} & \color{red}{\square} & \blacksquare \end{bmatrix} \to \begin{bmatrix} \square & \square & \square\\ \square & \blacksquare & \blacksquare\\ \blacksquare & \blacksquare & \blacksquare \end{bmatrix} \to \begin{bmatrix} \color{red}{\blacksquare} & \color{red}{\square} & \square\\ \color{red}{\square} & \color{red}{\blacksquare} & \blacksquare\\ \blacksquare & \blacksquare & \blacksquare \end{bmatrix} \\\to \begin{bmatrix} \color{red}{\blacksquare} & \blacksquare & \color{red}{\square}\\ \color{red}{\square} & \blacksquare & \color{red}{\blacksquare}\\ \blacksquare & \blacksquare & \blacksquare \end{bmatrix} \to \begin{bmatrix} \blacksquare & \blacksquare & \square\\ \blacksquare & \blacksquare & \blacksquare\\ \blacksquare & \blacksquare & \blacksquare \end{bmatrix} \to \begin{bmatrix} \blacksquare & \blacksquare & \blacksquare\\ \blacksquare & \blacksquare & \blacksquare\\ \blacksquare & \blacksquare & \blacksquare \end{bmatrix}$$

翻译中…

On queries where $M$ is not monotonic, the four squares highlighted in red denote cells that violate the condition stated above.

翻译中…

样例

Input #1
2
3 9
2 2
3 3
2 3
3 1
3 2
1 1
1 2
2 1
1 3
5 17
2 1
4 5
4 1
3 3
3 1
3 5
1 3
1 5
1 1
5 3
5 5
5 1
1 4
5 2
5 4
1 2
2 5
Output #1
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
InputCopy OutputCopy
题目信息
题号
2202G1
时间限制
4 s
内存限制
512 MB
标签
数据结构

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