Under construction

Still being built. Things may change

Sequence and Queries 35

Time limit7sMemory limit512 MB

Summary
Given a permutation, each query rotates a subarray right by k positions, then asks whether the array has an increasing subsequence of length 3.
Level

Hard8 of 10

Topics
Segment tree, Array, Implementation
Solved
No attempts yet

Problem

A sequence A1,A2,…,ANA_1, A_2, \ldots, A_N of length NN is given. Every number in the sequence is between 11 and NN inclusive, and all numbers are distinct. Write a program that processes the following query.

  • l r k: Shift the subarray [Al,Al+1,…,Ar][A_l, A_{l+1}, \ldots, A_r] right by kk positions. That is, AlA_l becomes Al+kA_{l+k}, Ar−kA_{r-k} becomes ArA_r, Ar−k+1A_{r-k+1} becomes AlA_l, and ArA_r becomes Al+k−1A_{l+k-1}. After the shift, print YES if the sequence contains an increasing subsequence of length 3, and NO otherwise.

Input

The first line contains the size NN of the sequence. (1≤N≤120,0001 \le N \le 120,000)

The second line contains A1,A2,…,ANA_1, A_2, \ldots, A_N. All numbers are distinct. (1≤Ai≤N1 \le A_i \le N)

The third line contains the number of queries MM. (1≤M≤120,0001 \le M \le 120,000)

The next MM lines each contain one query. (1≤L≤R≤N1 \le L \le R \le N, 0≤K≤R−L+10 \le K \le R-L+1)

Output

Print the result of each query on its own line.

Examples4

  1. Example 1

    Input
    6
    2 5 6 1 3 4
    1
    1 6 5
    
    Expected output
    YES
    
  2. Example 2

    Input
    8
    5 1 2 8 7 6 3 4
    4
    2 4 2
    4 5 1
    1 3 2
    3 8 2
    
    Expected output
    YES
    YES
    YES
    YES
    
  3. Example 3

    Input
    5
    4 3 2 5 1
    2
    3 4 1
    1 2 1
    
    Expected output
    NO
    YES
    
  4. Example 4

    Input
    6
    6 5 4 3 2 1
    3
    1 1 0
    1 3 1
    2 5 3
    
    Expected output
    NO
    NO
    YES