No.3709 Unknown Treasure
タグ : / 解いたユーザー数 62
作問者 :
UT0911
/ テスター :
Problem Statement
Yu-T is hunting for treasure on a grid of $H\times W$ cells.
Each cell is represented by coordinates $(r, c) (1 \leq r \leq H, 1 \leq c \leq W)$. Here, $r$ is the row number counted from the top, and $c$ is the column number counted from the left.
Yu-T has obtained $N$ pieces of information in advance. The $i$-th piece of information indicates that there is no treasure in the rectangular region specified by the upper-left cell $(r_{1,i}, c_{1,i})$ and the lower-right cell $(r_{2,i}, c_{2,i})$.
Based on all the information, find the number of cells that may contain treasure.
Constraints
- All inputs are integers
- $1 \leq H, W \leq 2000$
- $1 \leq N \leq 2\times 10^5$
- $1 \leq r_{1,i} \leq r_{2,i} \leq H$
- $1 \leq c_{1,i} \leq c_{2,i} \leq W$
Input
$H$ $W$ $N$
$r_{1, 1}$ $c_{1, 1}$ $r_{2, 1}$ $c_{2, 1}$
$r_{1, 2}$ $c_{1, 2}$ $r_{2, 2}$ $c_{2, 2}$
$\vdots$
$r_{1, N}$ $c_{1, N}$ $r_{2, N}$ $c_{2, N}$
Output
Output the number of cells that may contain treasure.
Print a newline at the end.
Sample
Sample 1
Input
4 4 2 1 1 3 2 1 2 1 4
Output
8
Taking each piece of information into account gives the following. Here, x is a cell with no treasure, and . is a cell that may contain treasure.
.... xx.. xxxx
.... -> xx.. -> xx..
.... xx.. xx..
.... .... ....
The number of cells that may contain treasure is $8$, so output 8.
Sample 2
Input
3 3 3 1 1 3 1 1 2 3 2 1 3 3 3
Output
0
Taking each piece of information into account gives the following.
... x.. xx. xxx
... -> x.. -> xx. -> xxx
... x.. xx. xxx
Sample 3
Input
9 9 1 5 5 5 5
Output
80
Taking each piece of information into account gives the following.
......... .........
......... .........
......... .........
......... .........
......... -> ....#....
......... .........
......... .........
......... .........
......... .........
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。