CF1083F.The Fair Nut and Amusing Xor

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Fair Nut has two arrays aa and bb, consisting of nn numbers. He found them so long ago that no one knows when they came to him.

The Fair Nut often changes numbers in his arrays. He also is interested in how similar aa and bb are after every modification.

Let's denote similarity of two arrays as the minimum number of operations to apply to make arrays equal (every operation can be applied for both arrays). If it is impossible, similarity will be equal −1-1.

Per one operation you can choose a subarray with length kk (kk is fixed), and change every element aia_i, which belongs to the chosen subarray, to ai⊕xa_i \oplus x (xx can be chosen), where ⊕\oplus denotes the bitwise XOR operation.

Nut has already calculated the similarity of the arrays after every modification. Can you do it?

Note that you just need to calculate those values, that is you do not need to apply any operations.

公平坚果有两组数组 aa 和 bb,每组均包含 nn 个数字。这两组数组早已存在,以至于无人知晓它们何时来到他手中。

公平坚果经常修改其数组中的数字。同时,他也关心每次修改后数组 aa 与 bb 的相似程度。

我们定义两个数组的相似度为:使这两个数组相等所需执行的最少操作次数(每次操作可同时作用于两个数组)。若无法使两数组相等,则相似度定义为 −1-1。

每次操作中,你可以选择一个长度为 kk 的子数组(kk 是固定的),并将该子数组中每个元素 aia_i 替换为 ai⊕xa_i \oplus x(其中 xx 可任选),此处 ⊕\oplus 表示按位异或运算。

公平坚果已对每次修改后的数组计算出了相似度。你也能做到吗?

注意:你只需计算这些相似度的值,即无需实际执行任何操作。

输入格式

The first line contains three numbers nn, kk and qq (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5, 0≤q≤2⋅1050 \le q \le 2 \cdot 10^5) — the length of the arrays, the length of the subarrays, to which the operations are applied, and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2140 \le a_i \lt 2^{14}) — elements of array aa.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi<2140 \le b_i \lt 2^{14}) — elements of array bb.

Each of the next qq lines describes query and contains string ss and two integers pp and vv (1≤p≤n1 \le p \le n, 0≤v<2140 \le v \lt 2^{14}) — array, which this query changes («a» or «b» without quotes), index of changing element and its new value.

第一行包含三个整数 nn、kk 和 qq(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5,0≤q≤2⋅1050 \le q \le 2 \cdot 10^5)——分别表示数组的长度、操作所作用的子数组长度,以及查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2140 \le a_i \lt 2^{14})——数组 aa 的元素。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi<2140 \le b_i \lt 2^{14})——数组 bb 的元素。

接下来的 qq 行每行描述一个查询,包含一个字符串 ss 和两个整数 pp、vv(1≤p≤n1 \le p \le n,0≤v<2140 \le v \lt 2^{14})——分别表示本次查询所修改的数组(为 «a» 或 «b»,不带引号)、待修改元素的下标以及其新值。

输出格式

On the first line print initial similarity of arrays aa and bb.

On the ii-th of following qq lines print similarity of aa and bb after applying first ii modifications.

在第一行输出数组 aa 和 bb 的初始相似度。

在接下来的 qq 行中,第 ii 行输出对 aa 和 bb 执行前 ii 次修改后的相似度。

输入输出样例

  • 输入#1

    3 3 1
    0 4 2
    1 2 3
    b 2 5

    输出#1

    -1
    1
  • 输入#2

    3 2 2
    1 3 2
    0 0 0
    a 1 0
    b 1 1

    输出#2

    2
    -1
    2

说明/提示

In the first sample making arrays [0,4,2][0, 4, 2] and [1,2,3][1, 2, 3] is impossible with k=3k=3. After the modification, you can apply the operation with x=1x=1 to the whole first array (its length is equal to kk), and it will be equal to the second array.

In order to make arrays equal in the second sample before changes, you can apply operations with x=1x=1 on subarray [1,2][1, 2] of aa and with x=2x=2 on subarray [2,3][2, 3] of bb.

After all queries arrays will be equal [0,3,2][0, 3, 2] and [1,0,0][1, 0, 0]. The same operations make them equal [1,2,2][1, 2, 2].

在第一个样例中,当 k=3k=3 时,无法通过操作将数组 [0,4,2][0, 4, 2] 和 [1,2,3][1, 2, 3] 变为相等。修改后,你可以对第一个数组(其长度等于 kk)整体应用 x=1x=1 的操作,使其变为第二个数组。

在第二个样例中,为使修改前的两个数组相等,你可以在 aa 的子数组 [1,2][1, 2] 上应用 x=1x=1 的操作,并在 bb 的子数组 [2,3][2, 3] 上应用 x=2x=2 的操作。

所有查询执行完毕后,两个数组将分别为 [0,3,2][0, 3, 2] 和 [1,0,0][1, 0, 0]。同样的操作可使它们均变为 [1,2,2][1, 2, 2]。

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

首页