Under construction

Still being built. Things may change

Guess the Data Structure

Time limit5sMemory limit256 MB

Summary
Maintain an array that supports appending values, range sum queries, xoring every element with x, and sorting the array.
Level

Hard8 of 10

Topics
Bit manipulation, Trie, Sorting, Prefix sum
Solved
No attempts yet

Problem

You are given an array AA of nn integers, numbered from 1 to nn. Process mm queries of the following kinds:

  1. Append integer xjx_j to the end of the array AA.
  2. Output the value of ∑i=ljrjAi\sum_{i=l_j}^{r_j} A_i (lj≤rjl_j \leq r_j).
  3. Replace each element AiA_i with Ai⊕xjA_i \oplus x_j, where ⊕\oplus is bitwise XOR.
  4. Sort the array AA.

Implement a data structure that processes these queries.

Input

The first line contains nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^{5}), the initial size of AA. The second line contains nn integers AiA_i (0≤Ai≤1090 \leq A_i \leq 10^{9}). The third line contains mm (1≤m≤2⋅1051 \leq m \leq 2 \cdot 10^{5}), the number of queries. Each of the next mm lines is one query in one of these formats: 1 xjx_j, 2 ljl_j rjr_j, 3 xjx_j, or 4.

For queries of types 1 and 3, 0≤xj≤1090 \leq x_j \leq 10^{9}. For queries of type 2, ljl_j and rjr_j are within the bounds of the array. Each test case has at least one query of type 2.

Output

For each query of type 2, output its sum on a separate line.

Examples1

  1. Example 1

    Input
    5
    3 4 7 3 6
    7
    3 5
    2 2 4
    4
    1 15
    2 3 6
    3 1
    2 1 6
    
    Expected output
    9
    30
    33