CF1517H.Fly Around the World

普及/提高-

通过率:0%

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 , xibixi+x_i^-\le b_i\le x_i^+ should be satisfied for all integers ii between 11 and nn , where xix_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, yibibi1yi+y_i^-\le b_i-b_{i-1}\le y_i^+ should be satisfied for all integers ii between 22 and nn , where yiy_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(bibi1)(bi1bi2)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 ziz_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.

输入格式

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

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

The ii -th of the next nn lines contains two integers xix_i^- , xi+x_i^+ ( 108xixi+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 n1n-1 lines contains two integers yi+1y_{i+1}^- , yi+1+y_{i+1}^+ ( 108yi+1yi+1+108-10^8\le y_{i+1}^-\le y_{i+1}^+\le 10^8 ) denoting the lower and upper bound of bi+1bib_{i+1}-b_i .

The ii -th of the next n2n-2 lines contains two integers zi+2z_{i+2}^- , zi+2+z_{i+2}^+ ( 108zi+2zi+2+108-10^8\le z_{i+2}^-\le z_{i+2}^+\le 10^8 ) denoting the lower and upper bound of (bi+2bi+1)(bi+1bi)(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 200000200\,000 .

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

输出格式

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.

输入输出样例

  • 输入#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=y2b2b1y2+=11=y_2^-\le b_2-b_1\le y_2^+=1 , b2b1b_2-b_1 must be 11 . So b2=1b_2=1 and b1=0b_1=0 must hold. Then by 1=y3b3b2y3+=11=y_3^-\le b_3-b_2\le y_3^+=1 , b3b_3 equals 22 . This contradicts the constraint of b31b_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 .

首页