CF1722E.Counting Rectangles

普及/提高-

通过率:0%

时间限制:6.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have nn rectangles, the ii-th rectangle has height hih_i and width wiw_i.

You are asked qq queries of the form hs ws hb wbh_s \ w_s \ h_b \ w_b.

For each query output, the total area of rectangles you own that can fit a rectangle of height hsh_s and width wsw_s while also fitting in a rectangle of height hbh_b and width wbw_b. In other words, print ∑hi⋅wi\sum h_i \cdot w_i for ii such that hs<hi<hbh_s \lt h_i \lt h_b and ws<wi<wbw_s \lt w_i \lt w_b.

Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.

Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

你有 nn 个矩形,其中第 ii 个矩形的高度为 hih_i,宽度为 wiw_i。

接下来会有 qq 个查询,每个查询的形式为 hs ws hb wbh_s \ w_s \ h_b \ w_b。

对于每个查询,请输出:你所拥有的、既能容纳一个高度为 hsh_s、宽度为 wsw_s 的矩形,又能被完全放入一个高度为 hbh_b、宽度为 wbw_b 的矩形中的所有矩形的总面积。换言之,对所有满足 hs<hi<hbh_s \lt h_i \lt h_b 且 ws<wi<wbw_s \lt w_i \lt w_b 的下标 ii,计算并输出 ∑hi⋅wi\sum h_i \cdot w_i。

请注意:若两个矩形高度相等或宽度相等,则它们无法互相嵌套(即不能“放入”对方)。此外,矩形不可旋转。

还请注意:某些测试用例的答案可能超出 32 位整数范围,因此请在编程语言中至少使用 64 位整数类型(例如 C++ 中的 long long)。

输入格式

The first line of the input contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case two integers n,qn, q (1≤n≤1051 \leq n \leq 10^5; 1≤q≤1051 \leq q \leq 10^5) — the number of rectangles you own and the number of queries.

Then nn lines follow, each containing two integers hi,wih_i, w_i (1≤hi,wi≤10001 \leq h_i, w_i \leq 1000) — the height and width of the ii-th rectangle.

Then qq lines follow, each containing four integers hs,ws,hb,wbh_s, w_s, h_b, w_b (1≤hs<hb, ws<wb≤10001 \leq h_s \lt h_b,\ w_s \lt w_b \leq 1000) — the description of each query.

The sum of qq over all test cases does not exceed 10510^5, and the sum of nn over all test cases does not exceed 10510^5.

输入的第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)——测试用例的数量。

每个测试用例的第一行包含两个整数 n,qn, q(1≤n≤1051 \leq n \leq 10^5;1≤q≤1051 \leq q \leq 10^5)——你拥有的矩形数量以及查询数量。

接下来是 nn 行,每行包含两个整数 hi,wih_i, w_i(1≤hi,wi≤10001 \leq h_i, w_i \leq 1000)——第 ii 个矩形的高度和宽度。

然后是 qq 行,每行包含四个整数 hs,ws,hb,wbh_s, w_s, h_b, w_b(1≤hs<hb, ws<wb≤10001 \leq h_s \lt h_b,\ w_s \lt w_b \leq 1000)——每个查询的描述。

所有测试用例中 qq 的总和不超过 10510^5,所有测试用例中 nn 的总和也不超过 10510^5。

输出格式

For each test case, output qq lines, the ii-th line containing the answer to the ii-th query.

对于每个测试用例,输出 qq 行,其中第 ii 行包含第 ii 个查询的答案。

输入输出样例

  • 输入#1

    3
    2 1
    2 3
    3 2
    1 1 3 4
    5 5
    1 1
    2 2
    3 3
    4 4
    5 5
    3 3 6 6
    2 1 4 5
    1 1 2 10
    1 1 100 100
    1 1 3 3
    3 1
    999 999
    999 999
    999 998
    1 1 1000 1000

    输出#1

    6
    41
    9
    0
    54
    4
    2993004

说明/提示

In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a 1×11 \times 1 rectangle inside of it and fit into a 3×43 \times 4 rectangle.

Only the 2×32 \times 3 rectangle works, because 1<21 \lt 2 (comparing heights) and 1<31 \lt 3 (comparing widths), so the 1×11 \times 1 rectangle fits inside, and 2<32 \lt 3 (comparing heights) and 3<43 \lt 4 (comparing widths), so it fits inside the 3×43 \times 4 rectangle. The 3×23 \times 2 rectangle is too tall to fit in a 3×43 \times 4 rectangle. The total area is 2⋅3=62 \cdot 3 = 6.

在第一个测试用例中,仅有一个查询。我们需要求出所有能容纳一个 1×11 \times 1 矩形、且自身又能被容纳于一个 3×43 \times 4 矩形内的矩形的面积之和。

只有 2×32 \times 3 矩形满足条件,因为 1<21 \lt 2(高度比较)且 1<31 \lt 3(宽度比较),因此 1×11 \times 1 矩形可放入其中;同时 2<32 \lt 3(高度比较)且 3<43 \lt 4(宽度比较),因此该矩形可放入 3×43 \times 4 矩形内。而 3×23 \times 2 矩形高度过大,无法放入 3×43 \times 4 矩形中。总面积为 2⋅3=62 \cdot 3 = 6。

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

首页