#P5283. [十二省联考 2019] 异或粽子

    ID: 4225 远端评测题 3500ms 1024MiB 尝试: 1 已通过: 1 难度: 8 上传者: 标签>2019各省省选二叉堆字典树,Trie 树

[十二省联考 2019] 异或粽子

Description

Xiao Zong is a good kid who likes eating zongzi. Today, she started making zongzi at home by herself.

There are nn different kinds of zongzi fillings in front of her. She places them in a row and numbers them from left to right as 11 to nn. The ii-th kind of filling has a non-negative integer attribute value aia_i. Each kind of filling is available in unlimited quantity, so Xiao Zong will not be unable to make zongzi due to lack of ingredients. She plans to use these fillings to make kk zongzi.

Her method is: choose two integers ll and rr such that 1lrn1 \leqslant l \leqslant r \leqslant n, mix all fillings with indices in the range [l,r][l, r] to make one zongzi. The tastiness of the resulting zongzi is the xor sum of the attribute values of these fillings. (Xor is the operation we usually call xor, i.e. the ˆ operator in C/C++ or the xor operator in Pascal.)

Xiao Zong wants to taste different flavors, so she does not want to make more than one zongzi using the same set of fillings.

She wants the sum of tastiness of all the zongzi she makes to be as large as possible. Please help her compute this value.

Input Format

The first line contains two positive integers nn and kk, representing the number of fillings and the number of zongzi Xiao Zong plans to make.

The next line contains nn non-negative integers. The ii-th number is aia_i, representing the attribute value of the ii-th filling.

For all input data: 1n5×1051 \leqslant n \leqslant 5 \times 10^5, $1 \leqslant k \leqslant \min\left\{\frac{n(n-1)}{2},2 \times 10^{5}\right\}$, 0ai42949672950 \leqslant a_i \leqslant 4 294 967 295.

Output Format

Output one integer on a single line, representing the maximum possible sum of tastiness of the zongzi Xiao Zong can make.

3 2
1 2 3
6

Hint

Test Point nn kk
11, 22, 33, 44, 55, 66, 77, 88 103\leqslant 10^3 103\leqslant 10^3
99, 1010, 1111, 1212 5×105\leqslant 5 \times 10^5
1313, 1414, 1515, 1616 103\leqslant 10^3 2×105\leqslant 2 \times 10^5
1717, 1818, 1919, 2020 5×105\leqslant 5 \times 10^5

Translated by ChatGPT 5