Under construction

Still being built. Things may change

Sequence and Queries 16

Interview

Time limit2sMemory limit512 MB

Summary
Maintain an array under point updates and range queries that ask for the leftmost index of the minimum value in a subarray.
Level

Medium6 of 10

Topics
Segment tree, Array, Implementation, Divide and conquer
Solved
No attempts yet

Problem

You are given a sequence A1,A2,…,ANA_1, A_2, \ldots, A_N of length NN. Write a program that processes the following two kinds of queries.

  • 1 i v: Replace AiA_i with vv. (1≤i≤N1 \le i \le N, 1≤v≤1091 \le v \le 10^9)
  • 2 i j: Print the index of the smallest value among Ai,Ai+1,…,AjA_i, A_{i+1}, \ldots, A_j. If several elements share that smallest value, print the smallest index among them. (1≤i≤j≤N1 \le i \le j \le N)

Indices of the sequence start at 1.

Input

The first line contains the length of the sequence NN. (1≤N≤100,0001 \le N \le 100{,}000)

The second line contains A1,A2,…,ANA_1, A_2, \ldots, A_N. (1≤Ai≤1091 \le A_i \le 10^9)

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

Each of the next MM lines contains one query.

Output

For each query of type 2, print its answer on its own line, in the order the queries are given.

Examples1

  1. Example 1

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