#P10009. [集训队互测 2022] 线段树

[集训队互测 2022] 线段树

Background

Please note: this problem is not a segment tree template problem.

Problem Description

You are given a sequence a1,a2,ana_1,a_2,\cdots a_n of length nn. You need to perform a total of qq operations of the following two types:

  • 1 l r: Replace alra_{l\sim r} with its XOR difference. Formally, let bi:=ai xor ai1b_i := a_i \text{ xor } a_{i-1} (l<irl<i\leq r), and then for each l<irl<i\leq r, replace aia_i with bib_i.

  • 2 pos: Query the value of aposa_{pos}.

After all operations are completed, you also need to output the final sequence aa.

Input Format

The first line contains an integer TT, indicating that the input satisfies the constraints of the TT-th subtask.

The second line contains two integers n,qn,q, representing the length of the sequence and the number of operations.

The third line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n.

In the next qq lines, each line contains several numbers describing one operation. If it is the first type of operation, the line contains three numbers 1 l r. If it is the second type of operation, the line contains two numbers 2 pos.

Output Format

Suppose there are q2q_2 operations of the second type. Output a total of q2+nq_2+n lines.

In the first q2q_2 lines, output one integer per line, which is the answer to that query.

In the next nn lines, output one integer per line, which is the final sequence aa.

1
6 6
1 1 5 1 9 4
2 5
1 2 5
2 4
1 3 6
2 6
1 1 6
9
4
12
1
0
5
4
12
0

Hint

More samples can be found in the attached file. For the (i+1)(i + 1)-th sample, T=iT = i.

Sample 1 Explanation

Initially, a=[1,1,5,1,9,4]a=[1,1,5,1,9,4].

The first operation asks to output a5a_5. At this time, a5=9a_5=9, so output 99.

The second operation asks to replace a25a_{2\sim 5} with its XOR difference. a25a_{2\sim 5} is [1,5,1,9][1,5,1,9], and its XOR difference is [1,4,4,8][1,4,4,8]. Therefore, after this operation, the sequence aa becomes [1,1,4,4,8,4][1,1,4,4,8,4].

The third operation asks to output a4a_4. At this time, a4=4a_4=4, so output 44.

The fourth operation asks to replace a36a_{3\sim 6} with its XOR difference. a36a_{3\sim 6} is [4,4,8,4][4,4,8,4], and its XOR difference is [4,0,12,12][4,0,12,12]. Therefore, after this operation, the sequence aa becomes [1,1,4,0,12,12][1,1,4,0,12,12].

The fifth operation asks to output a6a_6. At this time, a6=12a_6=12, so output 1212.

The sixth operation asks to replace a16a_{1\sim 6} with its XOR difference. a16a_{1\sim 6} is [1,1,4,0,12,12][1,1,4,0,12,12], and its XOR difference is [1,0,5,4,12,0][1,0,5,4,12,0]. Therefore, after this operation, the sequence aa becomes [1,0,5,4,12,0][1,0,5,4,12,0].

The final sequence aa is [1,0,5,4,12,0][1,0,5,4,12,0].

Constraints and Notes

For all testdata, it is guaranteed that 1n2.5×1051\leq n\leq 2.5\times 10^5, 1q1051\leq q\leq 10^5, 0ai<2300\leq a_i< 2^{30}, 1lrn1\leq l\leq r\leq n, and 1posn1\leq pos\leq n.

Subtask ID nn\leq qq\leq Special Property Score Subtask Dependencies
11 2×1032\times 10^3 None 88 None
22 2.5×1052.5\times 10^5 10510^5 A 44
33 B 77
44 CD 1313
55 DE 1212
66 D 1616 55
77 E 1111
88 None 2929 1,2,3,4,5,6,71,2,3,4,5,6,7

Special Property A: i2,ai=0\forall i\geq 2, a_i=0.

Special Property B: 0ai10\leq a_i\leq 1.

Special Property C: Let cc be the number of non-zero positions in the sequence aa. Then c100c\leq 100.

Special Property D: For operation 11, it holds that l=1l=1 and r=nr=n.

Special Property E: There is no operation 22.

Translated by ChatGPT 5