CF2268B.What a SauSaGe! It's All Meat

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In SauSaGe City, there are nn different flavors of sausages. Reyhaneh, the Queen of SauSaGe City, keeps aia_i (ai<16a_i \lt 16) sausages of flavor ii in the royal warehouse.

Over time, the royal inventory undergoes qq updates. Each update is given in the form (p,x)(p, x), which means the number of sausages of flavor pp in the warehouse is changed to xx (i.e., ap:=xa_p := x).

Reyhaneh can perform the following operation on the sausages any number of times (possibly zero):

  • Choose an index 1≤i<n1 \leq i \lt n and an integer 1≤k≤51 \leq k \leq 5, then replace aia_i and ai+1a_{i+1} with ai⊕(3⋅k)a_i \oplus (3 \cdot k) and ai+1⊕(3⋅k)a_{i+1} \oplus (3 \cdot k), respectively, where ⊕\oplus denotes the bitwise XOR.

In SauSaGe City, a sausage flavor is called All-Meat if its quantity is divisible by 33. Three famous sausage critics — Shafi, Shafaghi, and Ghaffari — only like flavors that are All-Meat.

Before processing any updates, and after each of the qq 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?

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 qq inventory updates (ap:=xa_p := x) are permanent.

在萨萨格(SauSaGe)城中,共有 nn 种不同风味的香肠。萨萨格城的女王蕾亚内赫(Reyhaneh)在皇家仓库中储存了第 ii 种风味的香肠 aia_i 根(其中 ai<16a_i \lt 16)。

随着时间推移,皇家库存将经历 qq 次更新。每次更新以 (p,x)(p, x) 的形式给出,表示将仓库中第 pp 种风味香肠的数量修改为 xx(即 ap:=xa_p := x)。

蕾亚内赫可以对香肠执行以下操作任意多次(包括零次):

  • 选择一个下标 1≤i<n1 \leq i \lt n 和一个整数 1≤k≤51 \leq k \leq 5,然后将 aia_i 和 ai+1a_{i+1} 分别替换为 ai⊕(3⋅k)a_i \oplus (3 \cdot k) 和 ai+1⊕(3⋅k)a_{i+1} \oplus (3 \cdot k),其中 ⊕\oplus 表示按位异或运算。

在萨萨格城中,若某种香肠风味的数量能被 33 整除,则该风味被称为“全肉型”(All-Meat)。三位著名的香肠评论家——沙菲(Shafi)、沙法吉(Shafaghi)和加法里(Ghaffari)——只喜欢“全肉型”风味。

在处理任何更新之前,以及每次 qq 次更新之后,你都需要回答如下问题:若蕾亚内赫以最优方式执行任意次数的操作,三位评论家会喜欢的香肠风味种类数的最大可能值是多少?

注意:为回答每个状态而执行的操作仅为假设性操作,不会影响后续查询所用的数组。但 qq 次库存更新(即 ap:=xa_p := x)是永久生效的。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and qq (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5, 0≤q≤2⋅1050 \leq q \leq 2 \cdot 10^5) — the number of sausage flavors and the number of updates, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<160 \leq a_i \lt 16) — the initial numbers of sausages of each flavor.

Then qq lines follow, each containing two integers pp and xx (1≤p≤n1 \leq p \leq n, 0≤x<160 \leq x \lt 16), meaning that apa_p is replaced with xx.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

It is guaranteed that the sum of qq over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5,0≤q≤2⋅1050 \leq q \leq 2 \cdot 10^5)—— 分别表示香肠口味的种类数和更新操作的次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<160 \leq a_i \lt 16)—— 表示每种口味初始的香肠数量。

接下来是 qq 行,每行包含两个整数 pp 和 xx(1≤p≤n1 \leq p \leq n,0≤x<160 \leq x \lt 16),表示将 apa_p 替换为 xx。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot 10^5。

保证所有测试用例的 qq 之和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, output q+1q + 1 integers. The first integer denotes the answer for the initial array. The next qq integers denote the answer for each update.

对于每个测试用例,输出 q+1q + 1 个整数。第一个整数表示初始数组的答案;接下来的 qq 个整数分别表示每次更新后的答案。

输入输出样例

  • 输入#1

    3
    2 1
    10 3
    1 0
    3 3
    15 1 5
    3 0
    1 10
    2 0
    4 0
    1 2 3 4

    输出#1

    2 2 
    2 2 2 3 
    1

说明/提示

In the first test case, the initial array is [10,3][10, 3]. By choosing i=1i = 1 and k=1k = 1 (so we apply XOR with 33), we obtain [10⊕3,3⊕3]=[9,0][10 \oplus 3, 3 \oplus 3] = [9, 0], and both 99 and 00 are divisible by 33. After the update, the array becomes [0,3][0, 3], where both elements are already divisible by 33, so the answer is 22 in both states.

In the second test case, the initial array is [15,1,5][15, 1, 5]. By choosing i=2i = 2 and k=3k = 3 (XOR with 99), we get [15,1⊕9,5⊕9]=[15,8,12][15, 1 \oplus 9, 5 \oplus 9] = [15, 8, 12], and 1515 and 1212 are divisible by 33, so the answer is 22.

After the first update, the array is [15,1,0][15, 1, 0]. Again, two elements (1515 and 00) are divisible by 33, so the answer is 22.

After the second update, the array is [10,1,0][10, 1, 0]. Choosing i=1i = 1 and k=3k = 3 (XOR with 99) gives [10⊕9,1⊕9,0]=[3,8,0][10 \oplus 9, 1 \oplus 9, 0] = [3, 8, 0], where 33 and 00 are divisible by 33, so the answer remains 22.

在第一个测试用例中,初始数组为 [10,3][10, 3]。选择 i=1i = 1 和 k=1k = 1(即对元素执行与 33 的异或操作),得到 [10⊕3,3⊕3]=[9,0][10 \oplus 3, 3 \oplus 3] = [9, 0],其中 99 和 00 均能被 33 整除。更新后,数组变为 [0,3][0, 3],此时两个元素均已能被 33 整除,因此两种状态下的答案均为 22。

在第二个测试用例中,初始数组为 [15,1,5][15, 1, 5]。选择 i=2i = 2 和 k=3k = 3(即对元素执行与 99 的异或操作),得到 [15,1⊕9,5⊕9]=[15,8,12][15, 1 \oplus 9, 5 \oplus 9] = [15, 8, 12],其中 1515 和 1212 能被 33 整除,因此答案为 22。

第一次更新后,数组变为 [15,1,0][15, 1, 0]。此时仍有两个元素(1515 和 00)能被 33 整除,因此答案仍为 22。

第二次更新后,数组变为 [10,1,0][10, 1, 0]。选择 i=1i = 1 和 k=3k = 3(即对元素执行与 99 的异或操作),得到 [10⊕9,1⊕9,0]=[3,8,0][10 \oplus 9, 1 \oplus 9, 0] = [3, 8, 0],其中 33 和 00 能被 33 整除,因此答案仍为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页