GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 10 July 2022

[Solution] Train and Queries Codeforces Solution



C. Train and Queries
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 (1ui109). 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 (1aj,bj109). For each query,

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

 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:


Input

The first line of the input contains an integer t (1t104) —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: n and k (1n2105,1k2105) —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 (1ui109). The values u1,u2,,un are not necessarily different.

The following k lines contain two different integers aj and bj (1aj,bj109) 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 2105. Similarly, it is guaranteed that the sum of k values over all test cases in the test also does not exceed 2105

Output

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 yEsyesYes and YES will be recognized as a positive response).

No comments:

Post a Comment