Under construction

Still being built. Things may change

XOR Queries

Interview

Time limit2sMemory limit1024 MB

Summary
Given an array with point updates, find the i-th largest value after XOR-ing every element with x, for each type 2 query.
Level

Medium5 of 10

Topics
Trie, Bit manipulation
Solved
No attempts yet

Problem

A sequence of integers a=[a1,a2,…,aN]a=[a_1,a_2,\ldots,a_N] of length NN is given. Write a program that processes the following queries.

  • 11 ii xx: Change the value of aia_i to xx.
  • 22 ii xx: Print the ii-th largest value, counting duplicates, in the sequence [a1⊕x,a2⊕x,…,aN⊕x][a_1\oplus x,a_2\oplus x,\ldots,a_N\oplus x].

Here, a⊕ba\oplus b is the bitwise exclusive OR (xor) of aa and bb.

Input

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

The second line contains NN integers a1,a2,…,aNa_1,a_2,\ldots,a_N, separated by spaces. (0≤ai≤231−1)(0\le a_i\le 2^{31}-1)

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

From the fourth line on, QQ lines follow, each containing one query. Type 2 queries appear at least once. (1≤i≤N; 0≤x≤231−1)(1\le i\le N;\ 0\le x\le 2^{31}-1)

Output

For each type 2 query, print the result on its own line.

Examples1

  1. Example 1

    Input
    9
    1 2 3 4 5 6 7 8 9
    11
    2 1 7
    2 2 7
    2 3 7
    1 1 3
    1 2 3
    1 4 3
    2 1 12
    2 2 12
    2 3 12
    2 4 12
    2 5 12
    
    Expected output
    15
    14
    6
    15
    15
    15
    15
    11