#P10512. 序列合并

    ID: 10653 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心洛谷原创O2优化位运算洛谷月赛

序列合并

Problem Description

Given a non-negative integer sequence {an}\{a_n\} of length nn, you can perform kk operations. In each operation, you choose two adjacent numbers and merge them into their bitwise OR.

Formally, in one operation, you choose an index ii (1i<n1 \le i < n), and then the original sequence becomes $\{a_1,a_2,\cdots,a_i \operatorname{or} a_{i+1},a_{i+2},\cdots,a_n\}$.

Find the maximum possible value of the bitwise AND of all numbers after kk operations.

Input Format

The first line contains two positive integers n,kn, k.

The second line contains nn non-negative integers, where the ii-th non-negative integer is aia_i.

Output Format

Output one line containing one positive integer, which is the answer.

5 2
2 1 2 3 1
2

Hint

[Sample Explanation]

One valid plan:

  • In the first operation, merge the first and second numbers, and the sequence becomes {3,2,3,1}\{3,2,3,1\}.
  • In the second operation, merge the third and fourth numbers, and the sequence becomes {3,2,3}\{3,2,3\}.

The final bitwise AND of all numbers is 22. It can be proven that there is no better plan.

[Constraints]

  • For 25%25\% of the testdata, n20n \le 20.
  • For another 25%25\% of the testdata, k=n2k = n - 2.

For all testdata, it is guaranteed that 1k<n2×1051 \le k < n \le 2 \times 10^5, 0ai<2300 \le a_i < 2^{30}.

Translated by ChatGPT 5