#P1887D. Split

    ID: 8795 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchdata structuresdivide and conquerdsumathtreestwo pointers

Split

No submission language available for this problem.

Description

Let's call an array b1,b2,,bmb_1, b_2, \ldots, b_m (m2m \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 1i<m1 \le i < m such that every element from b1,,bib_1, \ldots, b_i is strictly smaller than every element from bi+1,,bmb_{i+1}, \ldots, b_m.

Given an array a1,a2,ana_1, a_2, \ldots a_n consisting of distinct integers from 11 to nn. There are qq queries. Each query consists of two numbers ll and rr. For each query, determine whether the array al,al+1,,ara_l, a_{l+1}, \ldots, a_r is good.

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

The second line contains nn distinct integers a1,a2,,ana_1, a_2, \ldots, a_n (1ann1 \le a_n \le n) — the elements of the array aa.

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

Each of the next qq lines contains two integers lil_i and rir_i (1li<rin1 \le l_i < r_i \le n) — the description of the ii-th query.

For each query, output "Yes" (without quotes) if the array al,al+1,,ara_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).

Input

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

The second line contains nn distinct integers a1,a2,,ana_1, a_2, \ldots, a_n (1ann1 \le a_n \le n) — the elements of the array aa.

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

Each of the next qq lines contains two integers lil_i and rir_i (1li<rin1 \le l_i < r_i \le n) — the description of the ii-th query.

Output

For each query, output "Yes" (without quotes) if the array al,al+1,,ara_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).

Sample Input 1

5
3 2 1 4 5
5
1 5
1 3
1 4
1 2
2 5

Sample Output 1

Yes
No
Yes
No
Yes

Sample Input 2

6
1 6 2 4 3 5
3
3 5
2 6
4 6

Sample Output 2

Yes
No
Yes

Note

In the first example:

  • The array [3,2,1,4,5][3,2,1,4,5] can be split into two parts: [3,2,1][3,2,1] and [4,5][4,5].
  • The array [3,2,1][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][3,2,1,4] can be split into two parts: [3,2,1][3,2,1] and [4][4].
  • The array [3,2][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][2,1,4,5] can be split into two parts: [2,1][2,1] and [4,5][4,5].

In the second example:

  • The array [2,4,3][2,4,3] can be split into two parts: [2][2] and [4,3][4,3].
  • The array [6,2,4,3,5][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][4,3,5] can be split into two parts: [4,3][4,3] and [5][5].