Under construction

Still being built. Things may change

XOR Game

Time limit3sMemory limit512 MB

Summary
Given an array with point updates, answer range queries for the index whose XOR with x is smallest or largest, breaking ties by the smallest index.
Level

Medium6 of 10

Topics
Segment tree, Trie, Bit manipulation
Solved
No attempts yet

Problem

Jaehyeon and Junhyeok's favorite game these days is the XOR game.

In the XOR game, given an array AA, the following queries are processed.

  • 1 ll rr xx: Among all ii satisfying l≤i≤rl \le i \le r, choose the AiA_i whose XOR with xx is the smallest, and print that ii. If several such ii exist, print the smallest one.
  • 2 ll rr xx: Under the same conditions, choose the AiA_i whose XOR with xx is the largest, and print that ii. If several such ii exist, print the smallest one.
  • 3 pp xx: Change ApA_p to xx.

Write a program that runs the XOR game for Jaehyeon and Junhyeok.

Input

The first line contains the size NN of the initial array. (1≤N≤100,000)(1 \le N \le 100,000)

The second line contains the NN elements AiA_i of the initial array. (0≤Ai≤107)(0 \le A_i \le 10^7)

The third line contains the number of queries QQ. (1≤Q≤50,000)(1 \le Q \le 50,000)

Each of the next QQ lines contains a query. (0≤x≤107(0 \le x \le 10^7, 1≤l≤r≤N1 \le l \le r \le N, 1≤p≤N)1 \le p \le N)

Output

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

Examples1

  1. Example 1

    Input
    7
    92 104 100 43 28 108 97
    9
    2 2 6 76
    1 3 4 66
    2 6 7 6
    3 6 16
    2 6 6 101
    1 7 7 69
    3 6 6
    2 1 3 108
    1 5 5 124
    
    Expected output
    4
    3
    6
    6
    7
    1
    5