#P15867. 【MX-X26-T3】「Cfz Round 7」GLACIES
【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 of length and a positive integer . It is guaranteed that for all , .
For the sequence , 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 .
Yuki defines one "Bigger" operation as:
- Choose a positive integer with , and change to .
Yuki wants to perform several "Bigger" operations (possibly times) to make the "Fish Value" of the sequence 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 reach its maximum possible value.
Input Format
This problem has multiple test cases.
The first line contains two integers , representing the subtask index of this test point and the number of test cases. The sample satisfies .
Then each test case is given as follows. For each test case:
- The first line contains two integers .
- The second line contains integers .
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 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 and perform the "Bigger" operation times, then choose and perform it times, making the sequence become , and the "Fish Value" equals . It can be proven that the maximum possible "Fish Value" of the sequence is , and at least operations are required.
For the 2nd test case, no matter what operations you do, the "Fish Value" of the sequence is always , so the answer is .
Constraints
Let denote the sum of within a single test point.
For all testdata, we have:
- ;
- , , ;
- For all , .
This problem uses bundled tests.
- Subtask 1 (15 points): , .
- Subtask 2 (18 points): , , .
- Subtask 3 (21 points): , , .
- Subtask 4 (21 points): , , .
- Subtask 5 (25 points): No special constraints.
Translated by ChatGPT 5