Codeforces Round 905 (Div. 1)
D
Split
Codeforces
2700
原题
← CE →
翻译中…

Let's call an array $b_1, b_2, \ldots, b_m$ ($m \ge 2$) good if it can be split into two parts such that all elements in the left part are strictly smaller than all elements in the right part. In other words, there must exist an index $1 \le i \lt m$ such that every element from $b_1, \ldots, b_i$ is strictly smaller than every element from $b_{i+1}, \ldots, b_m$.

翻译中…

Given an array $a_1, a_2, \ldots a_n$ consisting of distinct integers from $1$ to $n$. There are $q$ queries. Each query consists of two numbers $l$ and $r$. For each query, determine whether the array $a_l, a_{l+1}, \ldots, a_r$ is good.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 3 \cdot 10^5$) — the size of the array.

翻译中…

The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_n \le n$) — the elements of the array $a$.

翻译中…

The third line contains a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries.

翻译中…

Each of the next $q$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \lt r_i \le n$) — the description of the $i$-th query.

翻译中…

Output

翻译中…

For each query, output "Yes" (without quotes) if the array $a_l, a_{l+1}, \ldots, a_r$ is good, and "No" (without quotes) otherwise.

翻译中…

You can output "Yes" and "No" in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).

翻译中…

Note

翻译中…

In the first example:

翻译中…
  • The array $[3,2,1,4,5]$ can be split into two parts: $[3,2,1]$ and $[4,5]$.
  • The array $[3,2,1]$ cannot be split into two parts such that all elements in the left part are smaller than all elements in the right part.
  • The array $[3,2,1,4]$ can be split into two parts: $[3,2,1]$ and $[4]$.
  • The array $[3,2]$ cannot be split into two parts such that all elements in the left part are smaller than all elements in the right part.
  • The array $[2,1,4,5]$ can be split into two parts: $[2,1]$ and $[4,5]$.
翻译中…

In the second example:

翻译中…
  • The array $[2,4,3]$ can be split into two parts: $[2]$ and $[4,3]$.
  • The array $[6,2,4,3,5]$ cannot be split into two parts such that all elements in the left part are smaller than all elements in the right part.
  • The array $[4,3,5]$ can be split into two parts: $[4,3]$ and $[5]$.
翻译中…

样例

Input #1
5
3 2 1 4 5
5
1 5
1 3
1 4
1 2
2 5
Output #1
Yes
No
Yes
No
Yes
InputCopy OutputCopy
Input #2
6
1 6 2 4 3 5
3
3 5
2 6
4 6
Output #2
Yes
No
Yes
InputCopy OutputCopy
题目信息
题号
1887D
时间限制
3 s
内存限制
256 MB
标签
二分
数据结构
分治
并查集
数学
树
双指针

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