CF1702C.Train and Queries
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Along the railroad there are stations indexed from 1 to 109 . An express train always travels along a route consisting of n stations with indices u1,u2,…,un , where ( 1≤ui≤109 ). The train travels along the route from left to right. It starts at station u1 , then stops at station u2 , then at u3 , and so on. Station un — 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,…,un .
You are given k queries, each containing two different integers aj and bj ( 1≤aj,bj≤109 ). For each query, determine whether it is possible to travel by train from the station with index aj to the station with index bj .
For example, let the train route consist of 6 of stations with indices [ 3,7,1,5,1,4 ] and give 3 of the following queries:
- a1=3 , b1=5 It is possible to travel from station 3 to station 5 by taking a section of the route consisting of stations [ 3,7,1,5 ]. Answer: YES.
- a2=1 , b2=7 You cannot travel from station 1 to station 7 because the train cannot travel in the opposite direction. Answer: NO.
- a3=3 , b3=10 It is not possible to travel from station 3 to station 10 because station 10 is not part of the train's route. Answer: NO.
输入格式
The first line of the input contains an integer t ( 1≤t≤104 ) —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: n and k ( 1≤n≤2⋅105,1≤k≤2⋅105 ) —the number of stations the train route consists of and the number of queries.
The third line of each test case contains exactly n integers u1,u2,…,un ( 1≤ui≤109 ). The values u1,u2,…,un are not necessarily different.
The following k lines contain two different integers aj and bj ( 1≤aj,bj≤109 ) describing the query with index j .
It is guaranteed that the sum of n values over all test cases in the test does not exceed 2⋅105 . Similarly, it is guaranteed that the sum of k values over all test cases in the test also does not exceed 2⋅105
输出格式
For each test case, output on a separate line:
- YES, if you can travel by train from the station with index aj to the station with index bj
- 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.