欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1702C.Train and Queries
Train and Queries
Along the railroad there are stations indexed from to . An express train always travels along a route consisting of stations with indices , where (). The train travels along the route from left to right. It starts at station , then stops at station , then at , and so on. Station — 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 .
You are given queries, each containing two different integers and (). For each query, determine whether it is possible to travel by train from the station with index to the station with index .
For example, let the train route consist of of stations with indices [] and give of the following queries:
-
,
It is possible to travel from station to station by taking a section of the route consisting of stations []. Answer:
YES. -
,
You cannot travel from station to station because the train cannot travel in the opposite direction. Answer:
NO. -
,
It is not possible to travel from station to station because station is not part of the train's route. Answer:
NO.
Input
The first line of the input contains an integer () —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: and () —the number of stations the train route consists of and the number of queries.
The third line of each test case contains exactly integers (). The values are not necessarily different.
The following lines contain two different integers and () describing the query with index .
It is guaranteed that the sum of values over all test cases in the test does not exceed . Similarly, it is guaranteed that the sum of values over all test cases in the test also does not exceed
Output
For each test case, output on a separate line:
YES, if you can travel by train from the station with index to the station with indexNOotherwise.
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
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |