Codeforces Round 979 (Div. 2)
F
Orangutan Approved Subarrays
Codeforces
2400
原题
← EG1 →
翻译中…

Suppose you have an array $b$. Initially, you also have a set $S$ that contains all distinct elements of $b$. The array $b$ is called orangutan-approved if it can be emptied by repeatedly performing the following operation:

翻译中…
  • In one operation, select indices $l$ and $r$ ($1 \leq l \leq r \leq |b|$) such that $v = b_l = b_{l+1} = \ldots = b_r$ and $v$ is present in $S$. Remove $v$ from $S$, and simultaneously remove all $b_i$ such that $l \leq i \leq r$. Then, reindex the elements $b_{r+1}, b_{r+2}, \ldots$ as $b_l, b_{l+1}, \ldots$ accordingly.
翻译中…

You are given an array $a$ of length $n$ and $q$ queries.

翻译中…

Each query consists of two indices $l$ and $r$ ($1 \le l \le r \le n$), and you need to determine whether or not the subarray $a_{l}, a_{l+1}, \ldots, a_r$ is orangutan-approved.

翻译中…

Input

翻译中…

The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains integers $n$ and $q$ ($1 \leq n,q \leq 2 \cdot 10^5$) — the size of $a$ and the number of queries, respectively.

翻译中…

The following line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array $a$.

翻译中…

The following $q$ lines contain two integers $l$ and $r$ — the endpoints of the subarray for each query ($1 \leq l \leq r \leq n$).

翻译中…

It is guaranteed that the sum of $n$ and $q$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each query, output "YES" (without quotes) if the subarray from $l$ to $r$ is orangutan-approved, and "NO" (without quotes) otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

In the first query of the first testcase, the answer is YES.

翻译中…
  • Initially, $S=\{1,2\}$ and $b=[1,2,2,1]$
  • Select $l=2$ and $r=3$. Since $b_2=b_3=2$ is in $S$, we may erase $b_2$ and $b_3$ from the array, as well as erasing $2$ from $S$. The set $S$ becomes $\{1\}$ and the array becomes $[1,1]$.
  • Select $l=1$ and $r=2$. Since $b_1=b_2=1$ is in $S$, we may erase $b_1$ and $b_2$ from the array, as well as erasing $1$ from $S$. The set $S$ becomes $\{\}$ and the array becomes $[]$.
  • Since the array is now empty, we can say the original array is orangutan-approved.
翻译中…

In the first query of the second testcase, the answer is NO, because it can be shown that the subarray $[2,1,2,1]$ cannot become empty through any sequence of valid operations.

翻译中…

样例

Input #1
3
4 2
1 2 2 1
1 4
1 3
5 3
1 2 1 2 1
2 5
3 5
1 3
8 4
1 2 3 2 1 3 2 3
1 5
2 8
3 5
6 8
Output #1
YES
YES
NO
YES
YES
YES
NO
YES
YES
InputCopy OutputCopy
题目信息
题号
2030F
时间限制
3 s
内存限制
512 MB
标签
二分
数据结构
动态规划
贪心
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。