#abc377c. C - Avoid Knight Attack

C - Avoid Knight Attack

Score : 300300 points

问题陈述

有一个由 N2N^2 个方格组成的网格,其中包含 NN 行和 NN 列。用 (i,j)(i,j) 表示从顶部数第 ii 行(1iN1\leq i\leq N)和从左边数第 jj 列(1jN1\leq j\leq N)的方格。

每个方格要么是空的,要么上面放置了一个棋子。网格上放置了 MM 个棋子,第 kk 个(1kM1\leq k\leq M)棋子放置在方格 (ak,bk)(a_k,b_k) 上。

你想要在一个空方格上放置你的棋子,使得它不能被任何现有的棋子捕获

放置在方格 (i,j)(i,j) 上的棋子可以捕获满足以下任一条件的棋子:

  • 放置在方格 (i+2,j+1)(i+2,j+1)
  • 放置在方格 (i+1,j+2)(i+1,j+2)
  • 放置在方格 (i1,j+2)(i-1,j+2)
  • 放置在方格 (i2,j+1)(i-2,j+1)
  • 放置在方格 (i2,j1)(i-2,j-1)
  • 放置在方格 (i1,j2)(i-1,j-2)
  • 放置在方格 (i+1,j2)(i+1,j-2)
  • 放置在方格 (i+2,j1)(i+2,j-1)

在这里,涉及不存在的方格的条件被认为是永远不会满足的。

例如,放置在方格 (4,4)(4,4) 上的棋子可以捕获下图中蓝色方格上的棋子:

你可以在多少个方格上放置你的棋子?

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a grid of N2N^2 squares with NN rows and NN columns. Let (i,j)(i,j) denote the square at the ii-th row from the top (1iN)(1\leq i\leq N) and jj-th column from the left (1jN)(1\leq j\leq N).

Each square is either empty or has a piece placed on it. There are MM pieces placed on the grid, and the kk-th (1kM)(1\leq k\leq M) piece is placed on square (ak,bk)(a_k,b_k).

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j)(i,j) can capture pieces that satisfy any of the following conditions:

  • Placed on square (i+2,j+1)(i+2,j+1)
  • Placed on square (i+1,j+2)(i+1,j+2)
  • Placed on square (i1,j+2)(i-1,j+2)
  • Placed on square (i2,j+1)(i-2,j+1)
  • Placed on square (i2,j1)(i-2,j-1)
  • Placed on square (i1,j2)(i-1,j-2)
  • Placed on square (i+1,j2)(i+1,j-2)
  • Placed on square (i+2,j1)(i+2,j-1)

Here, conditions involving non-existent squares are considered to never be satisfied.

For example, a piece placed on square (4,4)(4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

Constraints

  • 1N1091\leq N\leq10^9
  • 1M2×1051\leq M\leq2\times10^5
  • 1akN,1bkN (1kM)1\leq a_k\leq N,1\leq b_k\leq N\ (1\leq k\leq M)
  • (ak,bk)(al,bl) (1k<lM)(a_k,b_k)\neq(a_l,b_l)\ (1\leq k\lt l\leq M)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aMa_M bMb_M

Output

Print the number of empty squares where you can place your piece without it being captured by any existing pieces.

Sample Input 1

8 6
1 4
2 1
3 8
4 5
5 2
8 3

Sample Output 1

38

The existing pieces can capture pieces placed on the squares shown in blue in the following figure:

Therefore, you can place your piece on the remaining 3838 squares.

Sample Input 2

1000000000 1
1 1

Sample Output 2

999999999999999997

Out of 101810^{18} squares, only 33 squares cannot be used: squares (1,1)(1,1), (2,3)(2,3), and (3,2)(3,2).

Note that the answer may be 2322^{32} or greater.

Sample Input 3

20 10
1 4
7 11
7 15
8 10
11 6
12 5
13 1
15 2
20 10
20 15

Sample Output 3

338