a709: Train and Queries ( 訓練和查詢 )
Tags : 1100 dp greedy
Accepted rate : 16人/20人 ( 80% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-08-07 16:23

Content

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 (1 ≤ ui ≤ 109). 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 (1 ≤ aj,bj ≤ 109). For each query, 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:

  • a1=3, b1=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.

  • a2=1, b2=7

    You cannot travel from station 1 to station 7 because the train cannot travel in the opposite direction. Answer: NO.

  • a3=3, b3=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.

沿著鐵路有索引從 1 到 109 的車站。快車總是沿著由 n 個車站組成的路線行駛,索引為 u1,u2,…,un,其中 (1 ≤ ui ≤ 109)。火車沿著從左到右的路線行駛。它從 u1 站開始,然後在 u2 站停止,然後在 u3 站停止,以此類推。 車站 u— 終點站。

火車可能會不止一次訪問同一個車站。也就是說,值 u1,u2,…,un 之間可能存在重複。

給你 k 個查詢,每個查詢包含兩個不同的整數 aj 和 bj (1 ≤ aj,bj ≤ 109)。對於每個查詢,確定是否可以乘坐火車從索引為 j 的車站到索引為 bj 的車站。

例如,讓火車路線由索引為 [3,7,1,5,1,4] 的 6 個車站組成,並給出以下查詢中的 3 個:

a1=3, b1=5
可以通過由車站 [3,7,1,5] 組成的部分路線從車站 3 前往車站 5。回答:是的。

a2=1, b2=7
您不能從 1 號站前往 7 號站,因為火車不能朝相反的方向行駛。答案:沒有。

a3=3, b3=10
無法從 3 號站前往 10 號站,因為 10 號站不是火車路線的一部分。答案:沒有。

Input

The first line of the input contains an integer t (1 ≤ t ≤ 104) —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 ≤ n ≤ 2⋅105, 1 ≤ k ≤ 2⋅105) —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 (1 ≤ u≤ 109). The values u1,u2,…,un are not necessarily different.

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

 

輸入的第一行包含一個整數 t (1 ≤ t ≤ 104) — 測試中的測試用例數。

測試用例的描述如下。

每個測試用例的第一行是空的。

每個測試用例的第二行包含兩個整數:n 和 k (1 ≤ n ≤ 2⋅105, 1 ≤ k ≤ 2⋅105)——列車路線所包含的站數和查詢數。

每個測試用例的第三行正好包含 n 個整數 u1,u2,…,un (1 ≤ ui ≤ 109)。 u1,u2,…,un 的值不一定不同。

以下 k 行包含兩個不同的整數 aj 和 bj (1 ≤ aj,bj ≤ 109) 描述索引為 j 的查詢。

保證測試中所有測試用例的n個值之和不超過2⋅105。 同理,保證測試中所有測試用例的k值之和也不超過2⋅105

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.

對於每個測試用例,在單獨的行上輸出:

輸出 YES,如果您可以從索引為 j 的車站乘火車前往索引為 bj 的車站
輸出 NO,其他情況。

Sample Input #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
Sample Output #1
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (10%): 0.5s , <1K
公開 測資點#1 (10%): 0.5s , <1K
公開 測資點#2 (10%): 0.5s , <1K
公開 測資點#3 (10%): 0.5s , <1M
公開 測資點#4 (10%): 0.5s , <1M
公開 測資點#5 (10%): 0.5s , <1M
公開 測資點#6 (10%): 0.5s , <1M
公開 測資點#7 (10%): 0.5s , <10M
公開 測資點#8 (10%): 0.5s , <10M
公開 測資點#9 (10%): 0.5s , <10M
Hint :
Tags:
1100 dp greedy
出處:
Codeforces Round #805 [管理者:
lamkinun@gma... (Kinda Lam)
]


ID User Problem Subject Hit Post Date
1159
asnewchien@g... (david chien)
a709
解題心得
77 2023-06-02 16:53