#P10218. [省选联考 2024] 魔法手杖
[省选联考 2024] 魔法手杖
Problem Description
Note: We provide a brief, formal statement at the end of the description.
City C is a capital of magic, famous for its top-level wizards. For a wizard, the most important things are, of course, the magic wand and the magic crystals embedded in it.
Each magic wand and each magic crystal can be measured by a magic value. The magic value of a wand is the minimum magic value among all crystals embedded in it.
Apprentice wizard little from City C wants to strengthen his wand. Before strengthening, his wand has crystals embedded, whose magic values are .
Little plans to use a powerful secret technique once to strengthen his wand. In this technique, he may choose any , and then change every crystal’s magic value from to , where denotes bitwise XOR. Due to little ’s limited ability, and are all integers in .
Little also finds that this technique can be strengthened in a targeted way. Specifically, he can spend stamina to apply targeted strengthening to the -th crystal, changing its value from what would become into . Since little is limited, the total stamina spent on targeted strengthening cannot exceed , and each crystal can be targeted at most once.
Little wants to know the maximum possible magic value of the wand after strengthening. He cannot compute it, so please help him.
Formally: Given and , where and , you need to find and satisfying:
- ;
- Under the above constraint, maximize $val(S,x)=\min(\min \limits_{i \in S}(a_i+x),\min \limits_{i \in U \backslash S}(a_i \oplus x))$.
You only need to output the maximum value of .
Input Format
This problem has multiple test cases. The first line contains two integers , denoting the subtask index and the number of test cases. In the samples, means the constraints are the same as those of subtask .
Then for each test case:
- The first line contains three integers .
- The second line contains integers , representing the initial magic values of the crystals.
- The third line contains integers , representing the stamina cost of targeted strengthening for each crystal.
Output Format
For each test case, output one integer per line: the maximum magic value little can obtain for the wand.
1 2
5 2 3
1 1 2 3 7
1 1 0 3 2
1 1 1
1
0
5
2
Hint
[Sample 1 Explanation]
- For the first test case, one feasible plan is: apply targeted strengthening to crystal (i.e. ) and choose . The final crystal magic values are , so the wand’s magic value is . It can be proven that no better plan exists.
- For the second test case, one feasible plan is: apply targeted strengthening to crystal (i.e. ) and choose .
[Sample 2]
See the attached xor2.in/ans.
This sample satisfies .
[Sample 3]
See the attached xor3.in/ans.
This sample satisfies .
[Sample 4]
See the attached xor4.in/ans.
This sample satisfies .
[Sample 5]
See the attached xor5.in/ans.
This sample satisfies .
[Sample 6]
See the attached xor6.in/ans.
This sample satisfies .
[Sample 7]
See the attached xor7.in/ans.
This sample satisfies .
[Subtasks]
Let be the sum of over all test cases in a test file. For all testdata:
- ;
- , ;
- ;
- ;
- ;
- .
| Subtask Index | Special Property | ||||
|---|---|---|---|---|---|
| / | |||||
| A | |||||
| B | |||||
| C | |||||
| / | |||||
- Special Property A: ; .
- Special Property B: ; , and at most one satisfies .
- Special Property C: ; .
[Notes]
The input file of this problem is large, so please use a faster input method.
In the judging environment, you may use the -bit signed integer type __int128, which can store integers in . Its usage is basically the same as other integer types.
Note that this type cannot be read or written using common I/O methods such as cin/cout or scanf/printf. We provide an implementation of __int128 I/O functions in the contestant directory for you to use.
Translated by ChatGPT 5