2x2 Placing

AtCoder
IDabc436_c
Time2000ms
Memory256MB
Difficulty
There is a grid with $N$ rows and $N$ columns. Let $(i,j)$ denote the cell at the $i$\-th row from the top and $j$\-th column from the left. Initially, nothing is placed on the grid. You will now perform $M$ operations. The $i$\-th operation $(1\leq i\leq M)$ is as follows: * Place a block that occupies a $2 \times 2$ region with cell $(R_i,C_i)$ as the top-left corner on the grid if and only if its position does not overlap with any other blocks already placed. More precisely, for the set of cells $S=\lbrace (R_i,C_i),(R_i+1,C_i),(R_i,C_i+1),(R_i+1,C_i+1)\rbrace$, if there exists a block already placed on the grid that occupies any cell in $S$, do nothing; otherwise, place a block that occupies all four cells in $S$. After performing all operations, find how many blocks are placed on the grid. ## Constraints * $2\leq N \leq 10^9$ * $1\leq M \leq 2\times 10^5$ * $1\leq R_i,C_i \leq N-1$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $M$ $R_1$ $C_1$ $R_2$ $C_2$ $\vdots$ $R_M$ $C_M$ [samples]
Samples
Input #1
4 3
1 1
2 2
2 3
Output #1
2

The following diagram shows the operations, where black-filled regions represent blocks and red-framed regions represent where the next block is to be placed.
![image](https://img.atcoder.jp/abc436/1b753f2091cbd846ec88f1b0f49144cf.png)

*   Operation $1$: Nothing is placed in the $2 \times 2$ region with cell $(1,1)$ as the top-left corner, so place a block there.
*   Operation $2$: Among the $2 \times 2$ region with cell $(2,2)$ as the top-left corner, there is already another block on cell $(2,2)$, so do nothing.
*   Operation $3$: Nothing is placed in the $2 \times 2$ region with cell $(2,3)$ as the top-left corner, so place a block there.

Thus, after performing all operations, two blocks are placed on the grid.
Input #2
1000000000 4
1 1
1 101
101 1
101 101
Output #2
4

Blocks can be placed in all operations.
Input #3
8 10
6 5
7 3
6 7
3 4
4 2
3 7
1 3
7 4
6 1
6 1
Output #3
8

There may exist $i,j\ (i\neq j)$ such that $(R_i,C_i)=(R_j,C_j)$.
API Response (JSON)
{
  "problem": {
    "name": "2x2 Placing",
    "description": {
      "content": "There is a grid with $N$ rows and $N$ columns. Let $(i,j)$ denote the cell at the $i$\\-th row from the top and $j$\\-th column from the left. Initially, nothing is placed on the grid. You will now perf",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc436_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid with $N$ rows and $N$ columns. Let $(i,j)$ denote the cell at the $i$\\-th row from the top and $j$\\-th column from the left. Initially, nothing is placed on the grid.\nYou will now perf...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments