JPRSプログラミングコンテスト2026#2 (AtCoder Beginner Contest 470)
C
增、减、异或
Inc, Dec, Xor
AtCoder
⌀ 1006
原题
←D →

增、减、异或AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is a length-$N$ integer sequence $A=(A_1,A_2,\ldots,A_N)$. Initially, all elements of $A$ are $0$.

给定一个长度为$N$的整数序列 $A=(A_1,A_2,\ldots,A_N)$。初始时,$A$ 中的所有元素均为 $0$。AI (CI翻译)

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

接下来给出 $Q$ 个询问,请按顺序处理。询问有以下两种类型,分别采用以下格式之一给出:AI (CI翻译)

  • 1 x: Increase the value of $A_x$ by $1$.
  • 2: For each $i=1,2,\ldots,N$, if $A_i \geq 1$, decrease the value of $A_i$ by $1$.
  • 1 x:将 $A_x$ 的值增加 $1$。
  • 2:对于每个 $i=1,2,\ldots,N$,若 $A_i \geq 1$,则将 $A_i$ 的值减少 $1$。
AI (CI翻译)

Find the bitwise $\mathrm{XOR}$ of $A_1,A_2,\ldots,A_N$ immediately after processing each query.

请在处理完每个询问后,求 $A_1,A_2,\ldots,A_N$ 的按位 $\mathrm{XOR}$。AI (CI翻译)

What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, denoted $A \oplus B$, is defined as follows: In the binary representation of $A \oplus B$, the digit in the $2^k$ ($k \geq 0$) place is $1$ if exactly one of the digits in the $2^k$ place of $A$ and $B$ in their binary representations is $1$, and $0$ otherwise. For example, $3 \oplus 5 = 6$ (in binary: $011 \oplus 101 = 110$). More generally, the bitwise $\mathrm{XOR}$ of $k$ non-negative integers $p_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 $p_1, p_2, p_3, \dots, p_k$.

什么是按位 $\mathrm{XOR}$?非负整数 $A$ 和 $B$ 的按位 $\mathrm{XOR}$,记作 $A \oplus B$,定义如下:在 $A \oplus B$ 的二进制表示中,$2^k$($k \geq 0$)位上的数字,当且仅当 $A$ 和 $B$ 的二进制表示中该位上的数字恰有一个为 $1$ 时为 $1$;否则为 $0$。例如,$3 \oplus 5 = 6$(二进制表示为:$011 \oplus 101 = 110$)。更一般地,$k$ 个非负整数 $p_1, p_2, p_3, \dots, p_k$ 的按位 $\mathrm{XOR}$ 定义为 $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$,可以证明,该值与 $p_1, p_2, p_3, \dots, p_k$ 的顺序无关。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le N\le 5\times 10^5$
  • $1\le Q\le 5\times 10^5$
  • $1\le x\le N$
  • All input values are integers.
  • $1\le N\le 5\times 10^5$
  • $1\le Q\le 5\times 10^5$
  • $1\le x\le N$
  • 输入的所有数值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

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

N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
AI (CI翻译)

Each query is given in one of the following $2$ formats:

每个询问采用以下两种格式之一给出:AI (CI翻译)

1 x

1 x
AI (CI翻译)

2

2
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $Q$ lines.

输出 $Q$ 行。AI (CI翻译)

The $i$-th line $(1\le i\le Q)$ should contain the bitwise $\mathrm{XOR}$ of $A_1,A_2,\ldots,A_N$ for $A$ immediately after processing the $i$-th query.

第 $i$ 行 $(1\le i\le Q)$ 应包含处理完第 $i$ 个询问后,$A_1,A_2,\ldots,A_N$ 的按位 $\mathrm{XOR}$。AI (CI翻译)

样例

Input #1
2 5
1 2
1 2
1 1
2
2
Output #1
1
2
3
1
0
After processing the first query, $A=(0,1)$. The bitwise $\mathrm{XOR}$ of $0,1$ is $1$, so output $1$ on the first line. After processing the second query, $A=(0,2)$. The bitwise $\mathrm{XOR}$ of $0,2$ is $2$, so output $2$ on the second line. After processing the third query, $A=(1,2)$. The bitwise $\mathrm{XOR}$ of $1,2$ is $3$, so output $3$ on the third line. After processing the fourth query, $A=(0,1)$. The bitwise $\mathrm{XOR}$ of $0,1$ is $1$, so output $1$ on the fourth line. After processing the fifth query, $A=(0,0)$. The bitwise $\mathrm{XOR}$ of $0,0$ is $0$, so output $0$ on the fifth line.
Input #2
3 8
1 2
1 3
1 1
1 2
1 1
2
1 3
1 1
Output #2
1
0
1
2
1
0
1
2
题目信息
题号
abc470_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。