#P15867. 【MX-X26-T3】「Cfz Round 7」GLACIES

    ID: 17917 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心O2优化位运算梦熊比赛

【MX-X26-T3】「Cfz Round 7」GLACIES

Background

愛してる過去の夜も / The nights of the past that I love.

今じゃ季節に煌めいてゆく / Now they also sparkle in time.

Problem Description

Yuki has a sequence aa of length nn and a positive integer mm. It is guaranteed that for all 1≤i≤n1 \le i \le n, 0≤ai<2m0 \le a_i \lt 2^m.

For the sequence aa, Yuki defines its "Fish Value" as:

$$a_1 \text{ and } a_2 \text{ and } \cdots \text{ and } a_n$$

That is, the result of bitwise AND over all numbers in the sequence aa.

Yuki defines one "Bigger" operation as:

  • Choose a positive integer ii with i≤ni \le n, and change aia_i to (2⋅ai) mod 2m(2 \cdot a_i) \bmod 2^m.

Yuki wants to perform several "Bigger" operations (possibly 00 times) to make the "Fish Value" of the sequence aa as large as possible.

You need to help her find the minimum number of "Bigger" operations needed to make the "Fish Value" of the sequence aa reach its maximum possible value.

Input Format

This problem has multiple test cases.

The first line contains two integers c,tc,t, representing the subtask index of this test point and the number of test cases. The sample satisfies c=0c=0.

Then each test case is given as follows. For each test case:

  • The first line contains two integers n,mn,m.
  • The second line contains nn integers a1,…,ana_1,\dots,a_n.

Output Format

For each test case, output one line containing one integer, which is the minimum number of "Bigger" operations required to make the "Fish Value" of the sequence aa reach the maximum possible value.

0 4
3 4
1 3 8
2 3
4 0
3 5
3 6 11
3 4
5 7 13
5
0
8
3

Hint

Explanation of Sample 1

For the 1st test case, you can choose i=1i=1 and perform the "Bigger" operation 33 times, then choose i=2i=2 and perform it 22 times, making the sequence aa become {8,12,8}\{8,12,8\}, and the "Fish Value" equals 88. It can be proven that the maximum possible "Fish Value" of the sequence aa is 88, and at least 55 operations are required.

For the 2nd test case, no matter what operations you do, the "Fish Value" of the sequence aa is always 00, so the answer is 00.

Constraints

Let ∑n\sum n denote the sum of nn within a single test point.

For all testdata, we have:

  • 1≤t≤5⋅1051 \le t \le 5\cdot10^5;
  • 1≤n≤5⋅1051 \le n \le 5\cdot 10^5, 1≤m≤601 \le m \le 60, ∑n≤5⋅105\sum n \le 5\cdot10^5;
  • For all 1≤i≤n1 \le i \le n, 0≤ai<2m0 \le a_i \lt 2^m.

This problem uses bundled tests.

  • Subtask 1 (15 points): n,m≤8n,m \le 8, ∑n≤8\sum n \le 8.
  • Subtask 2 (18 points): n≤103n \le 10^3, m≤10m \le 10, ∑n≤103\sum n \le 10^3.
  • Subtask 3 (21 points): n≤104n \le 10^4, m≤20m \le 20, ∑n≤104\sum n \le 10^4.
  • Subtask 4 (21 points): n≤105n \le 10^5, m≤30m \le 30, ∑n≤105\sum n \le 10^5.
  • Subtask 5 (25 points): No special constraints.

Translated by ChatGPT 5