好香肠!全是肉AI (CI翻译)
In SauSaGe City, there are $n$ different flavors of sausages. Reyhaneh, the Queen of SauSaGe City, keeps $a_i$ ($a_i \lt 16$) sausages of flavor $i$ in the royal warehouse.
在 SauSaGe City,有 $n$ 种不同口味的香肠。SauSaGe City 的女王 Reyhaneh 在皇家仓库中存放着 $a_i$($a_i \lt 16$)根 $i$ 号口味的香肠。AI (CI翻译)
Over time, the royal inventory undergoes $q$ updates. Each update is given in the form $(p, x)$, which means the number of sausages of flavor $p$ in the warehouse is changed to $x$ (i.e., $a_p := x$).
随着时间推移,皇家库存会进行 $q$ 次更新。每次更新以 $(p, x)$ 的形式给出,表示仓库中 $p$ 号口味的香肠数量变为 $x$(即 $a_p := x$)。AI (CI翻译)
Reyhaneh can perform the following operation on the sausages any number of times (possibly zero):
Reyhaneh 可以对香肠执行以下操作任意次(也可以一次都不执行):AI (CI翻译)
- Choose an index
$1 \leq i \lt n$and an integer$1 \leq k \leq 5$, then replace$a_i$and$a_{i+1}$with$a_i \oplus (3 \cdot k)$and$a_{i+1} \oplus (3 \cdot k)$, respectively, where$\oplus$denotes the bitwise XOR.
- 选择一个下标
$1 \leq i \lt n$和一个整数$1 \leq k \leq 5$,然后分别将$a_i$和$a_{i+1}$替换为$a_i \oplus (3 \cdot k)$和$a_{i+1} \oplus (3 \cdot k)$,其中$\oplus$表示按位异或。
In SauSaGe City, a sausage flavor is called All-Meat if its quantity is divisible by $3$. Three famous sausage critics — Shafi, Shafaghi, and Ghaffari — only like flavors that are All-Meat.
在 SauSaGe City,如果某种口味的香肠数量能被 $3$ 整除,就称它为全肉口味。三位著名的香肠评论家 Shafi、Shafaghi 和 Ghaffari 只喜欢全肉口味。AI (CI翻译)
Before processing any updates, and after each of the $q$ updates, you need to answer the following question: If Reyhaneh performs an arbitrary number of operations optimally, what is the maximum possible number of sausage flavors that the three critics would like?
在处理任何更新之前,以及每次更新之后,你都需要回答以下问题:如果 Reyhaneh 以最优方式执行任意次操作,三位评论家最多会喜欢多少种口味?AI (CI翻译)
Note: The operations you perform to find the answer for each state are hypothetical and do not affect the array for subsequent queries. However, the $q$ inventory updates ($a_p := x$) are permanent.
注意: 为求出每个状态的答案而执行的操作都是假设的,不会影响后续询问中的数组。不过,$q$ 次库存更新($a_p := x$)是永久生效的。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个输入包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $q$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq q \leq 2 \cdot 10^5$) — the number of sausage flavors and the number of updates, respectively.
每个测试用例的第一行包含两个整数 $n$ 和 $q$($2 \leq n \leq 2 \cdot 10^5$,$0 \leq q \leq 2 \cdot 10^5$),分别表示香肠口味的数量和更新次数。AI (CI翻译)
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \lt 16$) — the initial numbers of sausages of each flavor.
第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($0 \leq a_i \lt 16$),表示每种口味香肠的初始数量。AI (CI翻译)
Then $q$ lines follow, each containing two integers $p$ and $x$ ($1 \leq p \leq n$, $0 \leq x \lt 16$), meaning that $a_p$ is replaced with $x$.
接下来 $q$ 行,每行包含两个整数 $p$ 和 $x$($1 \leq p \leq n$,$0 \leq x \lt 16$),表示将 $a_p$ 替换为 $x$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
保证所有测试用例中 $n$ 的总和不超过 $2\cdot 10^5$。AI (CI翻译)
It is guaranteed that the sum of $q$ over all test cases does not exceed $2\cdot 10^5$.
保证所有测试用例中 $q$ 的总和不超过 $2\cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output $q + 1$ integers. The first integer denotes the answer for the initial array. The next $q$ integers denote the answer for each update.
对于每个测试用例,输出 $q + 1$ 个整数。第一个整数表示初始数组的答案,接下来的 $q$ 个整数依次表示每次更新后的答案。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, the initial array is $[10, 3]$. By choosing $i = 1$ and $k = 1$ (so we apply XOR with $3$), we obtain $[10 \oplus 3, 3 \oplus 3] = [9, 0]$, and both $9$ and $0$ are divisible by $3$. After the update, the array becomes $[0, 3]$, where both elements are already divisible by $3$, so the answer is $2$ in both states.
在第一个测试用例中,初始数组为 $[10, 3]$。选择 $i = 1$ 和 $k = 1$(即执行异或 $3$),可以得到 $[10 \oplus 3, 3 \oplus 3] = [9, 0]$,其中 $9$ 和 $0$ 都能被 $3$ 整除。更新后,数组变为 $[0, 3]$,其中两个元素本来就都能被 $3$ 整除,因此两个状态的答案都是 $2$。AI (CI翻译)
In the second test case, the initial array is $[15, 1, 5]$. By choosing $i = 2$ and $k = 3$ (XOR with $9$), we get $[15, 1 \oplus 9, 5 \oplus 9] = [15, 8, 12]$, and $15$ and $12$ are divisible by $3$, so the answer is $2$.
在第二个测试用例中,初始数组为 $[15, 1, 5]$。选择 $i = 2$ 和 $k = 3$(异或 $9$),可以得到 $[15, 1 \oplus 9, 5 \oplus 9] = [15, 8, 12]$。其中 $15$ 和 $12$ 能被 $3$ 整除,因此答案为 $2$。AI (CI翻译)
After the first update, the array is $[15, 1, 0]$. Again, two elements ($15$ and $0$) are divisible by $3$, so the answer is $2$.
第一次更新后,数组变为 $[15, 1, 0]$。同样有两个元素($15$ 和 $0$)能被 $3$ 整除,因此答案为 $2$。AI (CI翻译)
After the second update, the array is $[10, 1, 0]$. Choosing $i = 1$ and $k = 3$ (XOR with $9$) gives $[10 \oplus 9, 1 \oplus 9, 0] = [3, 8, 0]$, where $3$ and $0$ are divisible by $3$, so the answer remains $2$.
第二次更新后,数组变为 $[10, 1, 0]$。选择 $i = 1$ 和 $k = 3$(异或 $9$),可以得到 $[10 \oplus 9, 1 \oplus 9, 0] = [3, 8, 0]$,其中 $3$ 和 $0$ 能被 $3$ 整除,因此答案仍为 $2$。AI (CI翻译)
样例
3
2 1
10 3
1 0
3 3
15 1 5
3 0
1 10
2 0
4 0
1 2 3 4
2 2
2 2 2 3
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。