310785: CF1887D. Split

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Splittime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 < 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 < 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).

ExamplesInput
5
3 2 1 4 5
5
1 5
1 3
1 4
1 2
2 5
Output
Yes
No
Yes
No
Yes
Input
6
1 6 2 4 3 5
3
3 5
2 6
4 6
Output
Yes
No
Yes
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]$.

Output

题目大意:
给定一个由不同的整数组成的数组a,数组的长度为n,元素取值范围为1到n。问题是要判断数组a的某个连续子数组是否可以被分割成两部分,使得左部分的每个元素都严格小于右部分的每个元素。存在q个查询,每个查询由两个数字l和r组成,需要判断数组a中从第l个到第r个元素的子数组是否满足上述条件。

输入输出数据格式:
输入:
- 第一行是一个整数n(2≤n≤3×10^5),表示数组a的长度。
- 第二行包含n个不同的整数a_1, a_2, ..., a_n(1≤a_i≤n),表示数组a的元素。
- 第三行是一个整数q(1≤q≤3×10^5),表示查询的数量。
- 接下来的q行,每行包含两个整数l_i和r_i(1≤l_i
输出:
- 对于每个查询,如果子数组a_l, a_{l+1}, ..., a_r可以被分割成两部分满足条件,则输出"Yes",否则输出"No"。
- 输出可以是任何大小写形式的"Yes"或"No"。

示例:
输入:
```
5
3 2 1 4 5
5
1 5
1 3
1 4
1 2
2 5
```
输出:
```
Yes
No
Yes
No
Yes
```

注意:
- 在第一个例子中,数组[3,2,1,4,5]可以分割为[3,2,1]和[4,5],满足条件。
- 在第二个例子中,数组[2,4,3]可以分割为[2]和[4,3],满足条件。题目大意: 给定一个由不同的整数组成的数组a,数组的长度为n,元素取值范围为1到n。问题是要判断数组a的某个连续子数组是否可以被分割成两部分,使得左部分的每个元素都严格小于右部分的每个元素。存在q个查询,每个查询由两个数字l和r组成,需要判断数组a中从第l个到第r个元素的子数组是否满足上述条件。 输入输出数据格式: 输入: - 第一行是一个整数n(2≤n≤3×10^5),表示数组a的长度。 - 第二行包含n个不同的整数a_1, a_2, ..., a_n(1≤a_i≤n),表示数组a的元素。 - 第三行是一个整数q(1≤q≤3×10^5),表示查询的数量。 - 接下来的q行,每行包含两个整数l_i和r_i(1≤l_i

加入题单

上一题 下一题 算法标签: