#abc361g. G - Go Territory

    ID: 4228 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>来源atcoder数据结构并查集其他双指针扫描高级数据结构双指针

G - Go Territory

Score : 600600 points

问题陈述

在二维平面上有 NN 块石头。第 ii 块石头位于坐标 (Xi,Yi)(X_i, Y_i)。所有石头都位于第一象限的格点上(包括坐标轴)。

计算格点 (x,y)(x, y) 的数量,这些格点上没有放置石头,并且从 (x,y)(x, y)(1,1)(-1, -1) 不可能 通过反复向上、向下、向左或向右移动 11 个单位而不经过放置石头的坐标。

更精确地说,计算格点 (x,y)(x, y) 的数量,这些格点上没有放置石头,并且不存在一个有限的整数对序列 (x0,y0),,(xk,yk)(x_0, y_0), \ldots, (x_k, y_k) 满足以下所有四个条件:

  • (x0,y0)=(x,y)(x_0, y_0) = (x, y)
  • (xk,yk)=(1,1)(x_k, y_k) = (-1, -1)
  • 对于所有 0i<k0 \leq i < k,有 xixi+1+yiyi+1=1|x_i - x_{i+1}| + |y_i - y_{i+1}| = 1
  • 对于所有 0ik0 \leq i \leq k,在 (xi,yi)(x_i, y_i) 处没有石头。

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

Problem Statement

There are NN stones placed on a 22-dimensional plane. The ii-th stone is located at coordinates (Xi,Yi)(X_i, Y_i). All stones are located at lattice points in the first quadrant (including the axes).

Count the number of lattice points (x,y)(x, y) where no stone is placed and it is impossible to reach (1,1)(-1, -1) from (x,y)(x, y) by repeatedly moving up, down, left, or right by 11 without passing through coordinates where a stone is placed.

More precisely, count the number of lattice points (x,y)(x, y) where no stone is placed, and there does not exist a finite sequence of integer pairs (x0,y0),,(xk,yk)(x_0, y_0), \ldots, (x_k, y_k) that satisfies all of the following four conditions:

  • (x0,y0)=(x,y)(x_0, y_0) = (x, y).
  • (xk,yk)=(1,1)(x_k, y_k) = (-1, -1).
  • xixi+1+yiyi+1=1|x_i - x_{i+1}| + |y_i - y_{i+1}| = 1 for all 0i<k0 \leq i < k.
  • There is no stone at (xi,yi)(x_i, y_i) for all 0ik0 \leq i \leq k.

Constraints

  • 0N2×1050 \leq N \leq 2 \times 10^5
  • 0Xi,Yi2×1050 \leq X_i, Y_i \leq 2 \times 10^5
  • The pairs (Xi,Yi)(X_i, Y_i) are distinct.
  • All input values are integers.

Input

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

NN

X1X_1 Y1Y_1

\vdots

XNX_N YNY_N

Output

Print the number of lattice points that satisfy the conditions.

Sample Input 1

5
1 0
0 1
2 3
1 2
2 1

Sample Output 1

1

It is impossible to reach (1,1)(-1, -1) from (1,1)(1, 1).

Sample Input 2

0

Sample Output 2

0

There may be cases where no stones are placed.

Sample Input 3

22
0 1
0 2
0 3
1 0
1 4
2 0
2 2
2 4
3 0
3 1
3 2
3 4
5 1
5 2
5 3
6 0
6 4
7 0
7 4
8 1
8 2
8 3

Sample Output 3

6

There are six such points: (6,1),(6,2),(6,3),(7,1),(7,2),(7,3)(6, 1), (6, 2), (6, 3), (7, 1), (7, 2), (7, 3).