CF1702C.Train and Queries

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

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 (1≤ui≤1091 \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 (1≤aj,bj≤1091 \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.

铁路沿线有编号从 11 到 10910^9 的车站。一列特快列车始终沿一条由 nn 个车站组成的路线运行,这些车站的编号为 u1,u2,…,unu_1, u_2, \dots, u_n(其中 1≤ui≤1091 \le u_i \le 10^9)。列车按从左到右的顺序沿该路线行驶:从车站 u1u_1 出发,随后停靠车站 u2u_2,再停靠 u3u_3,依此类推,直至终点站 unu_n。

列车有可能多次访问同一车站,即 u1,u2,…,unu_1, u_2, \dots, u_n 中可能存在重复值。

你将收到 kk 个查询,每个查询包含两个不同的整数 aja_j 和 bjb_j(1≤aj,bj≤1091 \le a_j, b_j \le 10^9)。对每个查询,请判断是否能乘坐该列车从编号为 aja_j 的车站到达编号为 bjb_j 的车站。

例如,设列车路线由 66 个车站组成,编号依次为 [3,7,1,5,1,4][3, 7, 1, 5, 1, 4],并给出以下 33 个查询:

  • a1=3a_1 = 3, b1=5b_1 = 5
    可以从车站 33 出发,沿路线中的一段 [3,7,1,5][3, 7, 1, 5] 到达车站 55。答案:YES。
  • a2=1a_2 = 1, b2=7b_2 = 7
    无法从车站 11 到达车站 77,因为列车不能反向行驶。答案:NO。
  • a3=3a_3 = 3, b3=10b_3 = 10
    无法从车站 33 到达车站 1010,因为车站 1010 不在列车路线中。答案:NO。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \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 (1≤n≤2⋅105,1≤k≤2⋅1051 \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 (1≤ui≤1091 \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 (1≤aj,bj≤1091 \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 2⋅1052 \cdot 10^5. Similarly, it is guaranteed that the sum of kk values over all test cases in the test also does not exceed 2⋅1052 \cdot 10^5

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——表示测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行为一空行。

每个测试用例的第二行包含两个整数:nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤k≤2⋅1051 \le k \le 2 \cdot 10^5)——分别表示列车路线所含车站的数量以及查询的数量。

每个测试用例的第三行恰好包含 nn 个整数 u1,u2,…,unu_1, u_2, \dots, u_n(1≤ui≤1091 \le u_i \le 10^9)。这些值 u1,u2,…,unu_1, u_2, \dots, u_n 不一定互不相同。

接下来的 kk 行每行包含两个不同的整数 aja_j 和 bjb_j(1≤aj,bj≤1091 \le a_j, b_j \le 10^9),用于描述第 jj 个查询。

保证在整个测试中,所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5;同样地,所有测试用例的 kk 值之和也不超过 2⋅1052 \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).

对于每个测试用例,在单独的一行上输出:

  • 如果可以从索引为 aja_j 的车站乘火车到达索引为 bjb_j 的车站,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#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.

第一个测试用例在题目描述中已作解释。

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

首页