This page is still under construction.

Parts of this page are still being built. What you see may change.

Mascot Song

Interview

Time limit1sMemory limit32 MB

Summary
Maintain an array under point updates and left rotations, reporting the number of maximal strictly increasing runs after each query.
Level

Medium6 of 10

Topics
Array, Simulation
Solved
No attempts yet

Problem

Fuleco writes a song as a sequence A1,…,AnA_1, \ldots, A_n. A consecutive subarray Ai,…,AjA_i, \ldots, A_j (1≤i≤j≤n1 \le i \le j \le n) is a block when:

  • i=1i=1 or Ai≤Ai−1A_i \le A_{i-1}
  • j=nj=n or Aj≥Aj+1A_j \ge A_{j+1}
  • Ai<Ai+1<⋯<AjA_i < A_{i+1} < \cdots < A_j

Every element belongs to exactly one block.

You get the starting sequence and qq queries:

  • 1 x y: set Ax←yA_x \leftarrow y
  • 2 z: rotate the whole sequence left by zz (the first element wraps to the end)

After each query, print the current number of blocks.

Input

Line 1: nn.

Line 2: A1,…,AnA_1, \ldots, A_n.

Line 3: qq.

Next qq lines: queries (1 x y or 2 z).

Output

Print the block count after each query, one per line in order.

Constraints

2≤n≤200 0002 \le n \le 200\,000, 1≤Ai≤1091 \le A_i \le 10^9, 1≤q≤200 0001 \le q \le 200\,000.

Examples6

  1. Example 1

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

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

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

    Input
    4
    10 1 10 1
    2
    1 2 10
    2 3
    
    Expected output
    4
    3
    
  5. Example 5

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

    Input
    8
    1 3 2 4 5 1 6 7
    3
    2 4
    1 5 9
    2 2
    
    Expected output
    4
    4
    4