P26834 [AtCoder] Grid Graph
普及+
题目描述

Problem Description

There is a grid graph with $ H $ rows and $ W $ columns. The graph has vertices arranged in a grid with $ H $ rows and $ W $ columns, and edges only between adjacent vertices (up, down, left, right). Kujira wanted to paint the edges of this graph for fun, but found that $ N $ vertices had been marked with an 'x' by someone's prank. The $ i $-th 'x' mark is drawn at $ (r_i, c_i) $. Here, $ (a, b) $ represents the vertex at the $ a $-th row and $ b $-th column, with the top-left vertex being $ (1,1) $ and the bottom-right vertex being $ (H,W) $. Feeling uneasy about the 'x' marks, Kujira decided to paint only the edges connecting vertices without 'x' marks.

Kujira will paint all the edges he can. How many edges will Kujira paint?

Note that the output may not fit into a 32-bit integer.

Input Format

The input is given from the standard input in the following format:

$ H $ $ W $ $ N $ $ r_1 $ $ c_1 $ $ r_2 $ $ c_2 $ $ : $ $ r_N $ $ c_N $

The first line contains the number of rows $ H $, the number of columns $ W $, and the number of vertices marked with an 'x' $ N $ as space-separated integers.

When $N \geq 1$, the second to $ N+1 $-th lines contain the information about the positions of the vertices marked with an 'x' as space-separated integers. $r_i, c_i (1 \leq i \leq N, 1 \leq r_i \leq H, 1 \leq c_i \leq W)$ indicate that the vertex at the $ r_i $-th row and $ c_i $-th column is marked with an 'x'.

Output Format

Output the number of edges Kujira will paint.

Sample Input and Output

Sample Input #1

3 4 4
1 4
2 2
2 4
3 1

Sample Output #1

7

Sample Input #2

1 5 2
1 2
1 4

Sample Output #2

0

Sample Input #3

100000 100000 0

Sample Output #3

19999800000

Notes/Hints

Constraints

  • All inputs are integers.
  • $1 \leq H, W \leq 10^5$
  • $0 \leq N \leq 10^3$
  • $1 \leq r_i \leq H$
  • $1 \leq c_i \leq W$
  • No vertex is given more than once in the input. That is, for all $ i, j $ ($1 \leq i < j \leq N$), $r_i \neq r_j$ or $c_i \neq c_j$ holds.

Sample Explanation 1

Figure 1: Sample Input 1

Sample Explanation 2

Figure 2: Sample Input 2

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4 4 1 4 2 2 2 4 3 1
样例输出
7