CF1517H.Fly Around the World

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After hearing the story of Dr. Zhang, Wowo decides to plan his own flight around the world.

He already chose nn checkpoints in the world map. Due to the landform and the clouds, he cannot fly too high or too low. Formally, let bib_i be the height of Wowo's aircraft at checkpoint ii, xi−≤bi≤xi+x_i^-\le b_i\le x_i^+ should be satisfied for all integers ii between 11 and nn, where xi−x_i^- and xi+x_i^+ are given integers.

The angle of Wowo's aircraft is also limited. For example, it cannot make a 9090-degree climb. Formally, yi−≤bi−bi−1≤yi+y_i^-\le b_i-b_{i-1}\le y_i^+ should be satisfied for all integers ii between 22 and nn, where yi−y_i^- and yi+y_i^+ are given integers.

The final limitation is the speed of angling up or angling down. An aircraft should change its angle slowly for safety concerns. Formally, zi−≤(bi−bi−1)−(bi−1−bi−2)≤zi+z_i^- \le (b_i - b_{i-1}) - (b_{i-1} - b_{i-2}) \le z_i^+ should be satisfied for all integers ii between 33 and nn, where zi−z_i^- and zi+z_i^+ are given integers.

Taking all these into consideration, Wowo finds that the heights at checkpoints are too hard for him to choose. Please help Wowo decide whether there exists a sequence of real numbers b1,…,bnb_1, \ldots, b_n satisfying all the contraints above.

在听了张博士的故事后,Wowo 决定规划自己的一次环球飞行。

他已在世界地图上选定了 nn 个检查点。由于地形和云层的影响,他无法飞得过高或过低。形式化地,设 bib_i 表示 Wowo 的飞机在第 ii 个检查点处的高度,则对所有介于 11 到 nn 之间的整数 ii,必须满足 xi−≤bi≤xi+x_i^-\le b_i\le x_i^+,其中 xi−x_i^- 和 xi+x_i^+ 是给定的整数。

Wowo 的飞机的俯仰角也受到限制。例如,它不能进行 90∘90^\circ 的陡峭爬升。形式化地,对所有介于 22 到 nn 之间的整数 ii,必须满足 yi−≤bi−bi−1≤yi+y_i^-\le b_i-b_{i-1}\le y_i^+,其中 yi−y_i^- 和 yi+y_i^+ 是给定的整数。

最后的限制是俯仰角变化(即抬头或低头)的速度。出于安全考虑,飞机应缓慢改变其俯仰角。形式化地,对所有介于 33 到 nn 之间的整数 ii,必须满足 zi−≤(bi−bi−1)−(bi−1−bi−2)≤zi+z_i^- \le (b_i - b_{i-1}) - (b_{i-1} - b_{i-2}) \le z_i^+,其中 zi−z_i^- 和 zi+z_i^+ 是给定的整数。

综合考虑上述所有限制,Wowo 发现为各检查点选定合适高度十分困难。请帮助 Wowo 判断:是否存在一个实数序列 b1,…,bnb_1, \ldots, b_n 满足上述所有约束条件。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤66 6661 \le t \le 66\,666). Description of the test cases follows.

The first line of each test case contains a single integer nn (3≤n≤100 0003 \le n \le 100\,000).

The ii-th of the next nn lines contains two integers xi−x_i^-, xi+x_i^+ (−108≤xi−≤xi+≤108-10^8\le x_i^-\le x_i^+\le 10^8) denoting the lower and upper bound of bib_i.

The ii-th of the next n−1n-1 lines contains two integers yi+1−y_{i+1}^-, yi+1+y_{i+1}^+ (−108≤yi+1−≤yi+1+≤108-10^8\le y_{i+1}^-\le y_{i+1}^+\le 10^8) denoting the lower and upper bound of bi+1−bib_{i+1}-b_i.

The ii-th of the next n−2n-2 lines contains two integers zi+2−z_{i+2}^-, zi+2+z_{i+2}^+ (−108≤zi+2−≤zi+2+≤108-10^8\le z_{i+2}^-\le z_{i+2}^+\le 10^8) denoting the lower and upper bound of (bi+2−bi+1)−(bi+1−bi)(b_{i+2}-b_{i+1}) - (b_{i+1}-b_i).

It is guaranteed that the sum of nn over all test cases does not exceed 200 000200\,000.

It is guaranteed that relaxing every constraint by 10−610^{-6} (i.e., decrease xi−,yi−,zi−x_i^-, y_i^-, z_i^- by 10−610^{-6} and increase xi+,yi+,zi+x_i^+, y_i^+, z_i^+ by 10−610^{-6}) will not change the answer.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤66 6661 \le t \le 66\,666)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(3≤n≤100 0003 \le n \le 100\,000)。

接下来的 nn 行中,第 ii 行包含两个整数 xi−x_i^-、xi+x_i^+(−108≤xi−≤xi+≤108-10^8\le x_i^-\le x_i^+\le 10^8),表示 bib_i 的下界与上界。

接下来的 n−1n-1 行中,第 ii 行包含两个整数 yi+1−y_{i+1}^-、yi+1+y_{i+1}^+(−108≤yi+1−≤yi+1+≤108-10^8\le y_{i+1}^-\le y_{i+1}^+\le 10^8),表示 bi+1−bib_{i+1}-b_i 的下界与上界。

接下来的 n−2n-2 行中,第 ii 行包含两个整数 zi+2−z_{i+2}^-、zi+2+z_{i+2}^+(−108≤zi+2−≤zi+2+≤108-10^8\le z_{i+2}^-\le z_{i+2}^+\le 10^8),表示 (bi+2−bi+1)−(bi+1−bi)(b_{i+2}-b_{i+1}) - (b_{i+1}-b_i) 的下界与上界。

保证所有测试用例的 nn 值之和不超过 200 000200\,000。

保证将每个约束放宽 10−610^{-6}(即:将所有 xi−,yi−,zi−x_i^-, y_i^-, z_i^- 减小 10−610^{-6},并将所有 xi+,yi+,zi+x_i^+, y_i^+, z_i^+ 增大 10−610^{-6})不会改变答案。

输出格式

For each test case, output YES if a sequence b1,…,bnb_1,\ldots, b_n satisfying the constraints exists and NO otherwise. The sequence b1,…,bnb_1,\ldots, b_n is not required.

对于每个测试用例,如果存在满足约束条件的序列 b1,…,bnb_1,\ldots, b_n,则输出 YES;否则输出 NO。无需输出序列 b1,…,bnb_1,\ldots, b_n 本身。

输入输出样例

  • 输入#1

    4
    3
    0 1
    0 1
    0 1
    1 1
    1 1
    -100 100
    3
    -967 541
    -500 834
    -724 669
    -858 978
    -964 962
    -645 705
    4
    0 0
    0 1
    0 1
    1 1
    0 1
    0 1
    0 1
    0 0
    0 0
    4
    0 0
    33 34
    65 66
    100 100
    0 100
    0 100
    0 100
    0 0
    0 0

    输出#1

    NO
    YES
    YES
    NO

说明/提示

In the first test case, all bib_i's are in [0,1][0,1]. Because of the constraints 1=y2−≤b2−b1≤y2+=11=y_2^-\le b_2-b_1\le y_2^+=1, b2−b1b_2-b_1 must be 11. So b2=1b_2=1 and b1=0b_1=0 must hold. Then by 1=y3−≤b3−b2≤y3+=11=y_3^-\le b_3-b_2\le y_3^+=1, b3b_3 equals 22. This contradicts the constraint of b3≤1b_3\le 1. So no solution exists.

In the second test case, we can let all bib_i's be 00.

In the third test case, one possible solution is b1=0b_1=0, b2=1/3b_2=1/3, b3=2/3b_3=2/3, b4=1b_4=1.

在第一个测试用例中,所有 bib_i 均位于区间 [0,1][0,1] 内。由于约束条件 1=y2−≤b2−b1≤y2+=11=y_2^-\le b_2-b_1\le y_2^+=1,可知 b2−b1b_2-b_1 必须等于 11,因此必有 b2=1b_2=1 且 b1=0b_1=0。接着由 1=y3−≤b3−b2≤y3+=11=y_3^-\le b_3-b_2\le y_3^+=1 可得 b3=2b_3=2,但这与约束 b3≤1b_3\le 1 矛盾。因此该问题无解。

在第二个测试用例中,可令所有 bib_i 均为 00。

在第三个测试用例中,一个可行解为 b1=0b_1=0,b2=1/3b_2=1/3,b3=2/3b_3=2/3,b4=1b_4=1。

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

首页