A15225 | Train and Queries
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Along the railroad there are stations indexed from $1$ to $10^9$ . An express train always travels along a route consisting of $n$ stations with indices $u_1, u_2, \dots, u_n$ , where ( $1 \le u_i \le 10^9$ ). The train travels along the route from left to right. It starts at station $u_1$ , then stops at station $u_2$ , then at $u_3$ , and so on. Station $u_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 $u_1, u_2, \dots, u_n$ .
You are given $k$ queries, each containing two different integers $a_j$ and $b_j$ ( $1 \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 $a_j$ to the station with index $b_j$ .
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:
- $a_1 = 3$ , $b_1 = 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.
- $a_2 = 1$ , $b_2 = 7$ You cannot travel from station $1$ to station $7$ because the train cannot travel in the opposite direction. Answer: NO.
- $a_3 = 3$ , $b_3 = 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.
It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values $u_1, u_2, \dots, u_n$ .
You are given $k$ queries, each containing two different integers $a_j$ and $b_j$ ( $1 \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 $a_j$ to the station with index $b_j$ .
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:
- $a_1 = 3$ , $b_1 = 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.
- $a_2 = 1$ , $b_2 = 7$ You cannot travel from station $1$ to station $7$ because the train cannot travel in the opposite direction. Answer: NO.
- $a_3 = 3$ , $b_3 = 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 \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: $n$ and $k$ ( $1 \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 $n$ integers $u_1, u_2, \dots, u_n$ ( $1 \le u_i \le 10^9$ ). The values $u_1, u_2, \dots, u_n$ are not necessarily different.
The following $k$ lines contain two different integers $a_j$ and $b_j$ ( $1 \le a_j, b_j \le 10^9$ ) 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 \cdot 10^5$ . Similarly, it is guaranteed that the sum of $k$ values over all test cases in the test also does not exceed $2 \cdot 10^5$
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 \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 $n$ integers $u_1, u_2, \dots, u_n$ ( $1 \le u_i \le 10^9$ ). The values $u_1, u_2, \dots, u_n$ are not necessarily different.
The following $k$ lines contain two different integers $a_j$ and $b_j$ ( $1 \le a_j, b_j \le 10^9$ ) 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 \cdot 10^5$ . Similarly, it is guaranteed that the sum of $k$ values over all test cases in the test also does not exceed $2 \cdot 10^5$
输出格式
For each test case, output on a separate line:
- YES, if you can travel by train from the station with index $a_j$ to the station with index $b_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).
- YES, if you can travel by train from the station with index $a_j$ to the station with index $b_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).
输入输出样例
输入 #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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted