#abc203e. E - White Pawn

E - White Pawn

Score : 500500 points

问题描述

NN 为一个正整数。我们有一个 (2N+1)×(2N+1)(2N+1) \times (2N+1) 的网格,其中行编号从0到2N2N,列编号也从0到2N2N。用 (i,j)(i,j) 表示第 ii 行和第 jj 列的方格。

我们有一个白色兵(pawn),它最初位于 (0,N)(0, N)。另外,我们有 MM 个黑色兵,其中第 ii 个位于 (Xi,Yi)(X_i, Y_i)

当白色兵位于 (i,j)(i, j) 时,你可以执行以下操作之一来移动它:

  • 如果满足 0i2N10\leq i\leq 2N-10j2N0 \leq j\leq 2N,且 (i+1,j)(i+1,j) 不包含 黑色兵,则将白色兵移动到 (i+1,j)(i+1, j)
  • 如果满足 0i2N10\leq i\leq 2N-10j2N10 \leq j\leq 2N-1,且 (i+1,j+1)(i+1,j+1) 包含 黑色兵,则将白色兵移动到 (i+1,j+1)(i+1,j+1)
  • 如果满足 0i2N10\leq i\leq 2N-11j2N1 \leq j\leq 2N,且 (i+1,j1)(i+1,j-1) 包含 黑色兵,则将白色兵移动到 (i+1,j1)(i+1,j-1)

你不能移动黑色兵。

找出通过重复这些操作可以使白色兵到达 (2N,Y)(2N, Y)YY 值的数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Let NN be a positive integer. We have a (2N+1)×(2N+1)(2N+1)\times (2N+1) grid where rows are numbered 00 through 2N2N and columns are also numbered 00 through 2N2N. Let (i,j)(i,j) denote the square at Row ii and Column jj.

We have one white pawn, which is initially at (0,N)(0, N). Also, we have MM black pawns, the ii-th of which is at (Xi,Yi)(X_i, Y_i).

When the white pawn is at (i,j)(i, j), you can do one of the following operations to move it:

  • If 0i2N10\leq i\leq 2N-1, 0j2N0 \leq j\leq 2N hold and (i+1,j)(i+1,j) does not contain a black pawn, move the white pawn to (i+1,j)(i+1, j).
  • If 0i2N10\leq i\leq 2N-1, 0j2N10 \leq j\leq 2N-1 hold and (i+1,j+1)(i+1,j+1) does contain a black pawn, move the white pawn to (i+1,j+1)(i+1,j+1).
  • If 0i2N10\leq i\leq 2N-1, 1j2N1 \leq j\leq 2N hold and (i+1,j1)(i+1,j-1) does contain a black pawn, move the white pawn to (i+1,j1)(i+1,j-1).

You cannot move the black pawns.

Find the number of integers YY such that it is possible to have the white pawn at (2N,Y)(2N, Y) by repeating these operations.

Constraints

  • 1N1091 \leq N \leq 10^9
  • 0M2×1050 \leq M \leq 2\times 10^5
  • 1Xi2N1 \leq X_i \leq 2N
  • 0Yi2N0 \leq Y_i \leq 2N
  • (Xi,Yi)(Xj,Yj)(X_i, Y_i) \neq (X_j, Y_j) (ij)(i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

X1X_1 Y1Y_1

::

XMX_M YMY_M

Output

Print the answer.

Sample Input 1

2 4
1 1
1 2
2 0
4 2

Sample Output 1

3

We can move the white pawn to (4,0)(4,0), (4,1)(4,1), and (4,2)(4,2), as follows:

  • (0,2)(1,1)(2,1)(3,1)(4,2)(0,2)\to (1,1)\to (2,1)\to (3,1)\to (4,2)
  • (0,2)(1,1)(2,1)(3,1)(4,1)(0,2)\to (1,1)\to (2,1)\to (3,1)\to (4,1)
  • (0,2)(1,1)(2,0)(3,0)(4,0)(0,2)\to (1,1)\to (2,0)\to (3,0)\to (4,0)

On the other hand, we cannot move it to (4,3)(4,3) or (4,4)(4,4). Thus, we should print 33.

Sample Input 2

1 1
1 1

Sample Output 2

0

We cannot move the white pawn from (0,1)(0,1).

update @ 2024/3/10 09:16:24