#P5312. [Ynoi2011] 竞赛实验班

[Ynoi2011] 竞赛实验班

Description

There is an array AA of length nn, indexed starting from 11. You need to process mm operations of the following four types:

  1. Append a number xx to the end of array AA.
  2. Output i=lrAi\sum_{i=l}^{r}A_i.
  3. Change every number AiA_i in array AA to AixA_i\oplus x. (\oplus denotes the XOR operation.)
  4. Sort array AA in non-decreasing order.

Input Format

The first line contains an integer nn, the initial size of AA.
The next line contains nn non-negative integers AiA_i, representing each element in AA.
The next line contains an integer mm, the number of operations.
The next mm lines each describe one operation:

  • 1 x: the first operation, append xx to the end.
  • 2 l r: the second operation, query i=lrAi\sum_{i=l}^{r}A_i. It is guaranteed that 1lrn1\le l\le r\le n', where nn' is the length of the sequence at the time of the operation.
  • 3 x: the third operation, XOR every element with xx.
  • 4: the fourth operation, sort array AA.

Output Format

For each operation of the second type, output the answer.

5
5 2 6 2 0
5
2 1 5
1 2
3 7
2 2 6
4
15
23

Hint

Idea: WJMZBMR, Solution: WJMZBMR, Code: WJMZBMR, Data: WJMZBMR

1n,m105,0x,Ai1091\le n,\,m\le 10^5, 0\le x,A_i\le 10^9

Translated by ChatGPT 5