统计窗口中的黑色方格AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a grid with $N$ rows and $M$ columns. In the $i$-th row from the top, the squares from the $L_i$-th through $R_i$-th columns from the left are painted black, and the other squares are painted white.
给定一个有 $N$ 行 $M$ 列的网格。从上往下第 $i$ 行中,从左往右第 $L_i$ 列到第 $R_i$ 列的方格被涂成黑色,其余方格被涂成白色。AI (CI翻译)
You are given $Q$ queries. For each query, answer the following question.
给定 $Q$ 个询问,请分别回答以下问题。AI (CI翻译)
- You are given integers
$A,B,C,D$. Find the number of black squares contained in the rectangular region from the$A$-th through$B$-th rows from the top and from the$C$-th through$D$-th columns from the left.
- 给定整数
$A,B,C,D$。求从上往下第$A$行到第$B$行、从左往右第$C$列到第$D$列所围成的矩形区域内黑色方格的数量。
Constraints
约束条件
AI (CI翻译)$1 \le N,M,Q \le 2\times10^5$$1 \le L_i \le R_i \le M$- For each query,
$1 \le A \le B \le N$. - For each query,
$1 \le C \le D \le M$. - All input values are integers.
$1 \le N,M,Q \le 2\times10^5$$1 \le L_i \le R_i \le M$- 对于每个询问,
$1 \le A \le B \le N$。 - 对于每个询问,
$1 \le C \le D \le M$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N M Q
L_1 R_1
L_2 R_2
\vdots
L_N R_N
\mathrm{query}_1
\vdots
\mathrm{query}_Q
N M Q
L_1 R_1
L_2 R_2
\vdots
L_N R_N
\mathrm{query}_1
\vdots
\mathrm{query}_QAI (CI翻译)
Each query $\mathrm{query}_i ~ (1 \le i \le Q)$ is given in the form
每个询问 $\mathrm{query}_i ~ (1 \le i \le Q)$ 按以下格式给出:AI (CI翻译)
A B C D
A B C DAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $Q$ lines. The $i$-th line should contain the answer to the $i$-th query.
输出 $Q$ 行。第 $i$ 行应包含第 $i$ 个询问的答案。AI (CI翻译)
样例
3 6 3
2 4
1 1
4 6
1 2 1 4
2 3 3 6
1 1 5 6
4
3
0
10 20 12
3 8
1 4
12 19
5 14
2 2
9 17
1 20
6 11
16 20
7 7
2 8 4 15
6 10 1 9
3 4 1 4
1 10 1 20
4 9 10 18
5 5 1 20
1 6 8 8
8 10 13 20
2 7 1 5
6 9 6 16
3 10 18 20
7 10 7 12
40
15
0
70
27
1
2
5
11
26
8
12
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。