| Codeforces Round 1082 (Div. 2) |
|---|
| Finished |
This is the hard version of the problem. The difference between the versions is that in this version, the constraints on $$$n$$$ and $$$q$$$ are very large. 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 is a monochrome matrix $$$M$$$ of size $$$n \times n$$$, where all cells are initially white. Please solve $$$q$$$ queries of the following kind:
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.
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 \color{red}{2\,000\,000}$$$, $$$1 \le q \le \min(n^2,\color{red}{2\,000\,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 $$$\color{red}{2\,000\,000}$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases does not exceed $$$\color{red}{2\,000\,000}$$$.
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.
23 92 23 32 33 13 21 11 22 11 35 172 14 54 13 33 13 51 31 51 15 35 55 11 45 25 41 22 5
YESNOYESNOYESNONOYESYESYESNOYESNONOYESNONOYESNONOYESYESNOYESYESYES
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.
| Name |
|---|


