AT_abc477_f.Count Cells in a Window

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a grid with NN rows and MM columns. In the ii-th row from the top, the squares from the LiL_i-th through RiR_i-th columns from the left are painted black, and the other squares are painted white.

You are given QQ queries. For each query, answer the following question.

  • You are given integers A,B,C,DA,B,C,D. Find the number of black squares contained in the rectangular region from the AA-th through BB-th rows from the top and from the CC-th through DD-th columns from the left.

给你一个 NN 行 MM 列的网格。在从上往下数第 ii 行中,从左往右数第 LiL_i 列到第 RiR_i 列(含端点)的格子被涂成黑色,其余格子为白色。

你将收到 QQ 个查询。对每个查询,请回答以下问题:

  • 给定整数 A,B,C,DA,B,C,D,求从上往下数第 AA 行到第 BB 行(含端点)、从左往右数第 CC 列到第 DD 列(含端点)所构成的矩形区域内包含的黑色格子数量。

输入格式

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

NN MM QQ
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LNL_N RNR_N
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

Each query queryi (1≤i≤Q)\mathrm{query}_i ~ (1 \le i \le Q) is given in the form

AA BB CC DD

输入从标准输入中按以下格式给出:

NN MM QQ
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LNL_N RNR_N
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

每个查询 queryi (1≤i≤Q)\mathrm{query}_i ~ (1 \le i \le Q) 的格式为:

AA BB CC DD

输出格式

Output QQ lines. The ii-th line should contain the answer to the ii-th query.

输出 QQ 行。第 ii 行应包含第 ii 个查询的答案。

输入输出样例

  • 输入#1

    3 6 3
    2 4
    1 1
    4 6
    1 2 1 4
    2 3 3 6
    1 1 5 6

    输出#1

    4
    3
    0
  • 输入#2

    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

    输出#2

    40
    15
    0
    70
    27
    1
    2
    5
    11
    26
    8
    12

说明/提示

Sample 1 Explanation:

The black squares are located as shown in the figure above. The 11-st query asks for the number of black squares within the blue rectangle at the upper left, the 22-nd query within the red rectangle at the lower right, and the 33-rd query within the green rectangle at the upper right.

Thus, output 4,3,04, 3, 0, respectively.

Constraints

  • 1≤N,M,Q≤2×1051 \le N,M,Q \le 2\times10^5
  • 1≤Li≤Ri≤M1 \le L_i \le R_i \le M
  • For each query, 1≤A≤B≤N1 \le A \le B \le N.
  • For each query, 1≤C≤D≤M1 \le C \le D \le M.
  • All input values are integers.

样例 1 解释:

黑色方格的位置如上图所示。第 11 个查询要求计算左上角蓝色矩形区域内的黑色方格数量,第 22 个查询要求计算右下角红色矩形区域内的黑色方格数量,第 33 个查询要求计算右上角绿色矩形区域内的黑色方格数量。

因此,依次输出 4, 3, 04,\ 3,\ 0。

限制条件

  • 1≤N,M,Q≤2×1051 \le N,M,Q \le 2\times10^5
  • 1≤Li≤Ri≤M1 \le L_i \le R_i \le M
  • 对于每个查询,满足 1≤A≤B≤N1 \le A \le B \le N。
  • 对于每个查询,满足 1≤C≤D≤M1 \le C \le D \le M。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页