CF1859D.Andrey and Escape from Capygrad

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An incident occurred in Capygrad, the capital of Tyagoland, where all the capybaras in the city went crazy and started throwing mandarins. Andrey was forced to escape from the city as far as possible, using portals.

Tyagoland is represented by a number line, and the city of Capygrad is located at point 00. There are nn portals all over Tyagoland, each of which is characterised by four integers lil_i, rir_i, aia_i and bib_i (1≤li≤ai≤bi≤ri≤1091 \le l_i \le a_i \le b_i \le r_i \le 10^9). Note that the segment [ai,bi][a_i, b_i] is contained in the segment [li,ri][l_i, r_i].

If Andrey is on the segment [li,ri][l_i, r_i], then the portal can teleport him to any point on the segment [ai,bi][a_i, b_i]. Andrey has a pass that allows him to use the portals an unlimited number of times.

Andrey thinks that the point xx is on the segment [l,r][l, r] if the inequality l≤x≤rl \le x \le r is satisfied.

Andrey has qq options for where to start his escape, each option is characterized by a single integer xix_i — the starting position of the escape. He wants to escape from Capygrad as far as possible (to the point with the maximum possible coordinate). Help Andrey determine how far he could escape from Capygrad, starting at each of the qq positions.

一场突发事件发生在泰亚国首都卡皮格拉德,城中所有水豚突然发狂,开始向四处投掷橘子。安德烈被迫尽可能远地逃离这座城市,借助传送门。

泰亚国被表示为一条数轴,首都卡皮格拉德位于坐标点 00 处。泰亚国境内共有 nn 个传送门,每个传送门由四个整数 lil_i、rir_i、aia_i 和 bib_i(满足 1≤li≤ai≤bi≤ri≤1091 \le l_i \le a_i \le b_i \le r_i \le 10^9)刻画。注意:区间 [ai,bi][a_i, b_i] 完全包含于区间 [li,ri][l_i, r_i] 内。

若安德烈当前位于区间 [li,ri][l_i, r_i] 上,则该传送门可将他瞬移至区间 [ai,bi][a_i, b_i] 内的任意一点。安德烈拥有一张通行证,允许他无限次使用这些传送门。

安德烈认为点 xx 位于区间 [l,r][l, r] 上,当且仅当不等式 l≤x≤rl \le x \le r 成立。

安德烈共有 qq 种不同的逃生起始方案,每种方案由一个整数 xix_i 表示——即逃生的起始位置。他希望尽可能远离卡皮格拉德(即抵达坐标值最大的点)。请帮助安德烈确定:对于每一个起始位置 xix_i,他最多能逃到多远的位置。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of sets of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of portals.

Each of the next nn lines contains four integers lil_i, rir_i, aia_i, and bib_i (1≤li≤ai≤bi≤ri≤109)(1 \le l_i \le a_i \le b_i \le r_i \le 10^9) — the characteristics of the portals.

The next line contains a single integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of positions.

The following line contains qq integers x1,x2,…,xqx_1, x_2, \ldots, x_q (1≤xi≤1091 \le x_i \le 10^9) — the position from which Andrey will start his escape in the ii-th options.

It is guaranteed that the sum of nn and the sum of qq over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例组的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示传送门的数量。

接下来的 nn 行,每行包含四个整数 lil_i、rir_i、aia_i 和 bib_i(1≤li≤ai≤bi≤ri≤1091 \le l_i \le a_i \le b_i \le r_i \le 10^9),表示第 ii 个传送门的属性。

接下来一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示位置的数量。

下一行包含 qq 个整数 x1,x2,…,xqx_1, x_2, \ldots, x_q(1≤xi≤1091 \le x_i \le 10^9),表示 Andrey 在第 ii 种方案中开始逃逸的位置。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single line of qq integers, containing the answers to Andrey's questions.

对于每个测试用例,输出一行包含 qq 个整数,表示安德烈各个问题的答案。

输入输出样例

  • 输入#1

    5
    3
    6 17 7 14
    1 12 3 8
    16 24 20 22
    6
    10 2 23 15 28 18
    3
    3 14 7 10
    16 24 20 22
    1 16 3 14
    9
    2 4 6 8 18 23 11 13 15
    2
    1 4 2 3
    3 9 6 7
    3
    4 8 1
    5
    18 24 18 24
    1 8 2 4
    11 16 14 14
    26 32 28 30
    5 10 6 8
    9
    15 14 13 27 22 17 31 1 7
    6
    9 22 14 20
    11 26 13 24
    21 33 22 23
    21 33 25 32
    1 6 3 4
    18 29 20 21
    8
    11 23 16 5 8 33 2 21

    输出#1

    14 14 23 15 28 22 
    14 14 14 14 22 23 14 14 15 
    7 8 7 
    15 14 14 30 24 17 31 4 8 
    32 32 32 5 8 33 4 32

说明/提示

In the first test case:

Optimal actions when starting from each position:

  1. Use portal 11 and teleport to point b1=14b_1 = 14.
  2. Use portal 22 first and teleport to point 66, which is on the segment [l1,r1]=[6,17][l_1, r_1] = [6, 17], then use portal 11 and teleport to point b1=14b_1 = 14.
  3. Stay at point x3=23x_3=23 without using any portals.
  4. Stay at point x4=15x_4=15 without using any portals.
  5. Point x5=28x_5=28 is not on any segment, so Andrey won't be able to teleport anywhere.
  6. Point x6=18x_6=18 is only on the segment [l3,r3]=[16,24][l_3, r_3] = [16, 24], use portal 33 and teleport to point b3=22b_3 = 22.

In the fifth test case:

Optimal actions when starting from each position:

  1. Use portal 11 first and teleport to point 1515 on the segment [a1,b1]=[14,20][a_1, b_1] = [14, 20], then use portal 22 and teleport to point 2121, which is on the segment [l4,r4]=[21,33][l_4, r_4] = [21, 33] and on the segment [a2,b2]=[13,24][a_2, b_2] = [13, 24], then teleport to point b4=32b_4 = 32.
  2. Use portal 66 first and teleport to point 2020 on the segment [a6,b6]=[20,21][a_6, b_6] = [20, 21], then use portal 22 and teleport to point 2222, which is simultaneously on the segment [l4,r4]=[21,33][l_4, r_4] = [21, 33] and on the segment [a2,b2]=[13,24][a_2, b_2] = [13, 24], then teleport to point b4=32b_4 = 32.
  3. Perform the same actions as from the first position.
  4. Stay at point x4=5x_4=5 without using any portals.
  5. Point 88 is not on any segment, so Andrey won't be able to teleport anywhere.
  6. Stay at point x6=33x_6=33 without using any portals.
  7. Use portal 55 and teleport to point b5=4b_5 = 4.
  8. Perform the same actions as from the first position.

在第一个测试用例中:

从每个起始位置出发的最优操作如下:

  1. 使用第 11 个传送门,传送到点 b1=14b_1 = 14。
  2. 首先使用第 22 个传送门,传送到点 66(该点位于线段 [l1,r1]=[6,17][l_1, r_1] = [6, 17] 上),然后使用第 11 个传送门,传送到点 b1=14b_1 = 14。
  3. 停留在点 x3=23x_3 = 23,不使用任何传送门。
  4. 停留在点 x4=15x_4 = 15,不使用任何传送门。
  5. 点 x5=28x_5 = 28 不在任何线段上,因此安德烈无法进行任何传送。
  6. 点 x6=18x_6 = 18 仅位于线段 [l3,r3]=[16,24][l_3, r_3] = [16, 24] 上,使用第 33 个传送门,传送到点 b3=22b_3 = 22。

在第五个测试用例中:

从每个起始位置出发的最优操作如下:

  1. 首先使用第 11 个传送门,传送到点 1515(该点位于线段 [a1,b1]=[14,20][a_1, b_1] = [14, 20] 上),然后使用第 22 个传送门,传送到点 2121(该点同时位于线段 [l4,r4]=[21,33][l_4, r_4] = [21, 33] 和线段 [a2,b2]=[13,24][a_2, b_2] = [13, 24] 上),最后传送到点 b4=32b_4 = 32。
  2. 首先使用第 66 个传送门,传送到点 2020(该点位于线段 [a6,b6]=[20,21][a_6, b_6] = [20, 21] 上),然后使用第 22 个传送门,传送到点 2222(该点同时位于线段 [l4,r4]=[21,33][l_4, r_4] = [21, 33] 和线段 [a2,b2]=[13,24][a_2, b_2] = [13, 24] 上),最后传送到点 b4=32b_4 = 32。
  3. 执行与从第一个位置出发时相同的操作。
  4. 停留在点 x4=5x_4 = 5,不使用任何传送门。
  5. 点 88 不在任何线段上,因此安德烈无法进行任何传送。
  6. 停留在点 x6=33x_6 = 33,不使用任何传送门。
  7. 使用第 55 个传送门,传送到点 b5=4b_5 = 4。
  8. 执行与从第一个位置出发时相同的操作。

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

首页