パナソニックプログラミングコンテスト(AtCoder Beginner Contest 186)
翻译中…
Problem Statement
翻译中…
We have a grid with $H$ horizontal rows and $W$ vertical columns. Let Square $(i,j)$ be the square at the $i$-th row and $j$-th column.
翻译中…
There are $M$ obstacles on this grid. The $i$-th obstacle is at Square $(X_i, Y_i)$.
翻译中…
We have a rook, the chess piece, on Square $(1, 1)$. In one move, it can move to the right or downward through any number of squares without obstacles.
翻译中…
Find the number of squares the rook can reach in two moves or less.
翻译中…
Constraints
翻译中…
$1\leq H,W \leq 2\times 10^5$$0\leq M \leq 2\times 10^5$$1\leq X_i \leq H$$1\leq Y_i \leq W$$(X_i,Y_i) \neq (1,1)$$(X_i,Y_i)$are distinct.- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
H W M
X_1 Y_1
\vdots
X_M Y_M
翻译中…
Output
翻译中…
Print the number of squares the rook can reach in two moves or less.
翻译中…
样例
Input #1
4 3 2
2 2
3 3
Output #1
10
Every square without an obstacle can be reached in two moves or less.
Input #2
5 4 4
3 2
3 4
4 2
5 2
Output #2
14
Every square without an obstacle except $(4,4)$ and $(5,4)$ can be reached in two moves or less.
Input #3
200000 200000 0
Output #3
40000000000
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。