C. 自增、自减与异或 / Inc, Dec, Xor

    传统题 2000ms 256MiB

自增、自减与异或 / Inc, Dec, Xor

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

There is a length-NN integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N). Initially, all elements of AA are 00.

You will be given QQ queries, which should be processed in order. There are two types of queries, each given in one of the following formats:

  • 1 x: Increase the value of AxA_x by 11.
  • 2: For each i=1,2,,Ni=1,2,\ldots,N, if Ai1A_i \geq 1, decrease the value of AiA_i by 11.

Find the bitwise XOR\mathrm{XOR} of A1,A2,,ANA_1,A_2,\ldots,A_N immediately after processing each query.

What is bitwise XOR\mathrm{XOR}?

The bitwise XOR\mathrm{XOR} of non-negative integers AA and BB, denoted ABA \oplus B, is defined as follows:

  • In the binary representation of ABA \oplus B, the digit in the 2k2^k (k0k \geq 0) place is 11 if exactly one of the digits in the 2k2^k place of AA and BB in their binary representations is 11, and 00 otherwise.

For example, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).
More generally, the bitwise XOR\mathrm{XOR} of kk non-negative integers p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k is defined as $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$, and it can be proved that this value does not depend on the order of p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k.

Constraints

  • 1N5×1051\le N\le 5\times 10^5
  • 1Q5×1051\le Q\le 5\times 10^5
  • 1xN1\le x\le N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$ $Q$
$\text{query}_1$
$\text{query}_2$
$\vdots$
$\text{query}_Q$

Each query is given in one of the following 22 formats:

$1$ $x$
$2$

Output

Output QQ lines.

The ii-th line (1iQ)(1\le i\le Q) should contain the bitwise XOR\mathrm{XOR} of A1,A2,,ANA_1,A_2,\ldots,A_N for AA immediately after processing the ii-th query.

2 5
1 2
1 2
1 1
2
2
1
2
3
1
0

After processing the first query, A=(0,1)A=(0,1). The bitwise XOR\mathrm{XOR} of 0,10,1 is 11, so output 11 on the first line.

After processing the second query, A=(0,2)A=(0,2). The bitwise XOR\mathrm{XOR} of 0,20,2 is 22, so output 22 on the second line.

After processing the third query, A=(1,2)A=(1,2). The bitwise XOR\mathrm{XOR} of 1,21,2 is 33, so output 33 on the third line.

After processing the fourth query, A=(0,1)A=(0,1). The bitwise XOR\mathrm{XOR} of 0,10,1 is 11, so output 11 on the fourth line.

After processing the fifth query, A=(0,0)A=(0,0). The bitwise XOR\mathrm{XOR} of 0,00,0 is 00, so output 00 on the fifth line.

3 8
1 2
1 3
1 1
1 2
1 1
2
1 3
1 1
1
0
1
2
1
0
1
2

ABC470 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-8-10 17:00
结束于
2026-8-17 17:00
持续时间
168 小时
主持人
参赛人数
82