[Solution] Train and Queries Codeforces Solution
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:
The first line of the input contains an integer () —the number of test cases in the test.
Round Down the Price Codeforces Solution
Polycarp Writes a String from Memory Codeforces Solution
Train and Queries Codeforces Solution
Not a Cheap String Codeforces Solution
Split Into Two Sets Codeforces Solution
Equate Multisets Codeforces Solution
Passable Paths (easy version) Codeforces Solution
Passable Paths (hard version) Codeforces Solution
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
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 index
- 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).
No comments:
Post a Comment