CF1702C.Train and Queries
普及-
通过率:0%
时间限制:3.00s
内存限制:256MB
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.
铁路沿线有编号从 1 到 109 的车站。一列特快列车始终沿一条由 n 个车站组成的路线运行,这些车站的编号为 u1,u2,…,un(其中 1≤ui≤109)。列车按从左到右的顺序沿该路线行驶:从车站 u1 出发,随后停靠车站 u2,再停靠 u3,依此类推,直至终点站 un。
列车有可能多次访问同一车站,即 u1,u2,…,un 中可能存在重复值。
你将收到 k 个查询,每个查询包含两个不同的整数 aj 和 bj(1≤aj,bj≤109)。对每个查询,请判断是否能乘坐该列车从编号为 aj 的车站到达编号为 bj 的车站。
例如,设列车路线由 6 个车站组成,编号依次为 [3,7,1,5,1,4],并给出以下 3 个查询:
- a1=3, b1=5
可以从车站 3 出发,沿路线中的一段 [3,7,1,5] 到达车站 5。答案:YES。 - a2=1, b2=7
无法从车站 1 到达车站 7,因为列车不能反向行驶。答案:NO。 - a3=3, b3=10
无法从车站 3 到达车站 10,因为车站 10 不在列车路线中。答案: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
输入的第一行包含一个整数 t(1≤t≤104)——表示测试用例的数量。
随后是各测试用例的描述。
每个测试用例的第一行为一空行。
每个测试用例的第二行包含两个整数:n 和 k(1≤n≤2⋅105,1≤k≤2⋅105)——分别表示列车路线所含车站的数量以及查询的数量。
每个测试用例的第三行恰好包含 n 个整数 u1,u2,…,un(1≤ui≤109)。这些值 u1,u2,…,un 不一定互不相同。
接下来的 k 行每行包含两个不同的整数 aj 和 bj(1≤aj,bj≤109),用于描述第 j 个查询。
保证在整个测试中,所有测试用例的 n 值之和不超过 2⋅105;同样地,所有测试用例的 k 值之和也不超过 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).
对于每个测试用例,在单独的一行上输出:
- 如果可以从索引为 aj 的车站乘火车到达索引为 bj 的车站,则输出 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测评打分。不知道怎么写?