CF1702C.Train and Queries

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Along the railroad there are stations indexed from 11 to 10910^9 . An express train always travels along a route consisting of nn stations with indices u1,u2,,unu_1, u_2, \dots, u_n , where ( 1ui1091 \le u_i \le 10^9 ). The train travels along the route from left to right. It starts at station u1u_1 , then stops at station u2u_2 , then at u3u_3 , and so on. Station unu_n — the terminus.

It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values u1,u2,,unu_1, u_2, \dots, u_n .

You are given kk queries, each containing two different integers aja_j and bjb_j ( 1aj,bj1091 \le a_j, b_j \le 10^9 ). For each query, determine whether it is possible to travel by train from the station with index aja_j to the station with index bjb_j .

For example, let the train route consist of 66 of stations with indices [ 3,7,1,5,1,43, 7, 1, 5, 1, 4 ] and give 33 of the following queries:

  • a1=3a_1 = 3 , b1=5b_1 = 5 It is possible to travel from station 33 to station 55 by taking a section of the route consisting of stations [ 3,7,1,53, 7, 1, 5 ]. Answer: YES.
  • a2=1a_2 = 1 , b2=7b_2 = 7 You cannot travel from station 11 to station 77 because the train cannot travel in the opposite direction. Answer: NO.
  • a3=3a_3 = 3 , b3=10b_3 = 10 It is not possible to travel from station 33 to station 1010 because station 1010 is not part of the train's route. Answer: NO.

输入格式

The first line of the input contains an integer tt ( 1t1041 \le t \le 10^4 ) —the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case is empty.

The second line of each test case contains two integers: nn and kk ( 1n2105,1k21051 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5 ) —the number of stations the train route consists of and the number of queries.

The third line of each test case contains exactly nn integers u1,u2,,unu_1, u_2, \dots, u_n ( 1ui1091 \le u_i \le 10^9 ). The values u1,u2,,unu_1, u_2, \dots, u_n are not necessarily different.

The following kk lines contain two different integers aja_j and bjb_j ( 1aj,bj1091 \le a_j, b_j \le 10^9 ) describing the query with index jj .

It is guaranteed that the sum of nn values over all test cases in the test does not exceed 21052 \cdot 10^5 . Similarly, it is guaranteed that the sum of kk values over all test cases in the test also does not exceed 21052 \cdot 10^5

输出格式

For each test case, output on a separate line:

  • YES, if you can travel by train from the station with index aja_j to the station with index bjb_j
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

输入输出样例

  • 输入#1

    3
    
    
    6 3
    3 7 1 5 1 4
    3 5
    1 7
    3 10
    
    
    3 3
    1 2 1
    2 1
    1 2
    4 5
    
    
    7 5
    2 1 1 1 2 4 4
    1 3
    1 4
    2 1
    4 1
    1 2

    输出#1

    YES
    NO
    NO
    YES
    YES
    NO
    NO
    YES
    YES
    NO
    YES

说明/提示

The first test case is explained in the problem statement.

首页