A12127 | Changing Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
At a break Vanya came to the class and saw an array of $n$ $k$ -bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$ -bit integer if $0 \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 $i$ ( $1 \leq i \leq n$ ) and replace the number $a_i$ with the number $\overline{a_i}$ . We define $\overline{x}$ for a $k$ -bit integer $x$ as the $k$ -bit integer such that all its $k$ bits differ from the corresponding bits of $x$ .
Vanya does not like the number $0$ . Therefore, he likes such segments $[l, r]$ ( $1 \leq l \leq r \leq n$ ) such that $a_l \oplus a_{l+1} \oplus \ldots \oplus a_r \neq 0$ , where $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.
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 $i$ ( $1 \leq i \leq n$ ) and replace the number $a_i$ with the number $\overline{a_i}$ . We define $\overline{x}$ for a $k$ -bit integer $x$ as the $k$ -bit integer such that all its $k$ bits differ from the corresponding bits of $x$ .
Vanya does not like the number $0$ . Therefore, he likes such segments $[l, r]$ ( $1 \leq l \leq r \leq n$ ) such that $a_l \oplus a_{l+1} \oplus \ldots \oplus a_r \neq 0$ , where $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $1 \leq n \leq 200\,000$ , $1 \leq k \leq 30$ ).
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \leq a_i \leq 2^k - 1$ ), separated by spaces — the array of $k$ -bit integers.
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \leq a_i \leq 2^k - 1$ ), separated by spaces — the array of $k$ -bit integers.
输出格式
Print one integer — the maximum possible number of segments with XOR not equal to $0$ that can be obtained by making several (possibly $0$ ) operations described in the statement.
输入输出样例
输入 #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 $5$ segments that Vanya likes. If he performs the operation with $i = 2$ , he gets an array $[1, 0, 0]$ , because $\overline{3} = 0$ when $k = 2$ . This array has $3$ segments that Vanya likes. Also, to get an array with $5$ segments that Vanya likes, he can perform two operations with $i = 3$ and with $i = 2$ . He then gets an array $[1, 0, 3]$ . It can be proven that he can't obtain $6$ or more segments that he likes.
In the second example, to get $19$ segments that Vanya likes, he can perform $4$ operations with $i = 3$ , $i = 4$ , $i = 5$ , $i = 6$ and get an array $[1, 4, 3, 0, 4, 3]$ .
In the second example, to get $19$ segments that Vanya likes, he can perform $4$ operations with $i = 3$ , $i = 4$ , $i = 5$ , $i = 6$ and get an array $[1, 4, 3, 0, 4, 3]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted