CF1702C.Train and Queries

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Train and Queries

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.

Input

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

Output

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).

Note

The first test case is explained in the problem statement.

Samples

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
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES

在线编程 IDE

建议全屏模式获得最佳体验