CF1054D.Changing Array

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

At a break Vanya came to the class and saw an array of nn kk-bit integers a1,a2,…,ana_1, a_2, \ldots, a_n on the board. An integer xx is called a kk-bit integer if 0≤x≤2k−10 \leq x \leq 2^k - 1.

Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array ii (1≤i≤n1 \leq i \leq n) and replace the number aia_i with the number ai‾\overline{a_i}. We define x‾\overline{x} for a kk-bit integer xx as the kk-bit integer such that all its kk bits differ from the corresponding bits of xx.

Vanya does not like the number 00. Therefore, he likes such segments [l,r][l, r] (1≤l≤r≤n1 \leq l \leq r \leq n) such that al⊕al+1⊕…⊕ar≠0a_l \oplus a_{l+1} \oplus \ldots \oplus a_r \neq 0, where ⊕\oplus denotes the bitwise XOR operation. Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.

课间时,万尼亚来到教室,看到黑板上写着一个由 nn 个 kk 位整数 a1,a2,…,ana_1, a_2, \ldots, a_n 构成的数组。若整数 xx 满足 0≤x≤2k−10 \leq x \leq 2^k - 1,则称其为 kk 位整数。

当然,万尼亚忍不住开始修改黑板上的数字。为了确保没人察觉,他只允许自己执行一种操作:选择数组的一个下标 ii(1≤i≤n1 \leq i \leq n),并将 aia_i 替换为 ai‾\overline{a_i}。对于任意 kk 位整数 xx,我们定义 x‾\overline{x} 为满足其所有 kk 位均与 xx 对应位相反的 kk 位整数。

万尼亚不喜欢数字 00。因此,他喜欢满足 al⊕al+1⊕…⊕ar≠0a_l \oplus a_{l+1} \oplus \ldots \oplus a_r \neq 0 的区间 [l,r][l, r](其中 1≤l≤r≤n1 \leq l \leq r \leq n),这里 ⊕\oplus 表示按位异或运算。请确定:在允许执行零次或多次上述操作的前提下,万尼亚最多能获得多少个他所喜欢的区间。

输入格式

The first line of the input contains two integers nn and kk (1≤n≤200 0001 \leq n \leq 200\,000, 1≤k≤301 \leq k \leq 30).

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤2k−10 \leq a_i \leq 2^k - 1), separated by spaces — the array of kk-bit integers.

输入的第一行包含两个整数 nn 和 kk(1≤n≤200 0001 \leq n \leq 200\,000,1≤k≤301 \leq k \leq 30)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤2k−10 \leq a_i \leq 2^k - 1),以空格分隔——该数组由 kk 位整数组成。

输出格式

Print one integer — the maximum possible number of segments with XOR not equal to 00 that can be obtained by making several (possibly 00) operations described in the statement.

输出一个整数——通过执行若干次(可能为 00 次)题目描述中的操作,所能得到的异或值不等于 00 的区间的最大可能数量。

输入输出样例

  • 输入#1

    3 2
    1 3 0

    输出#1

    5
  • 输入#2

    6 3
    1 4 4 7 3 4

    输出#2

    19

说明/提示

In the first example if Vasya does not perform any operations, he gets an array that has 55 segments that Vanya likes. If he performs the operation with i=2i = 2, he gets an array [1,0,0][1, 0, 0], because 3‾=0\overline{3} = 0 when k=2k = 2. This array has 33 segments that Vanya likes. Also, to get an array with 55 segments that Vanya likes, he can perform two operations with i=3i = 3 and with i=2i = 2. He then gets an array [1,0,3][1, 0, 3]. It can be proven that he can't obtain 66 or more segments that he likes.

In the second example, to get 1919 segments that Vanya likes, he can perform 44 operations with i=3i = 3, i=4i = 4, i=5i = 5, i=6i = 6 and get an array [1,4,3,0,4,3][1, 4, 3, 0, 4, 3].

在第一个例子中,如果瓦西娅不执行任何操作,他得到的数组包含 55 个凡娅喜欢的区间。如果他执行 i=2i = 2 的操作,则得到数组 [1,0,0][1, 0, 0],因为当 k=2k = 2 时,3‾=0\overline{3} = 0。该数组包含 33 个凡娅喜欢的区间。此外,为得到一个包含 55 个凡娅喜欢区间的数组,他也可以分别执行 i=3i = 3 和 i=2i = 2 的两次操作,从而得到数组 [1,0,3][1, 0, 3]。可以证明,他无法得到 66 个或更多凡娅喜欢的区间。

在第二个例子中,为得到 1919 个凡娅喜欢的区间,他可以执行 44 次操作,分别取 i=3i = 3、i=4i = 4、i=5i = 5、i=6i = 6,从而得到数组 [1,4,3,0,4,3][1, 4, 3, 0, 4, 3]。

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

首页