## GUPTA MECHANICAL

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

# [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 ${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,

Solution Click Below:-  👉
👇👇👇👇👇

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:

Input

The first line of the input contains an integer $t$ ($1\le t\le {10}^{4}$) —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$ ($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}$

Output

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