#abc304g. G - Max of Medians
G - Max of Medians
Score : points
问题描述
给定一个长度为 的序列:。
通过重新排列序列 中的元素,找出长度为 的序列 $(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})$ 的中位数可能达到的最大值。
此处, 表示按位异或运算。
什么是按位异或运算?非负整数 和 的按位异或(记作 )定义如下:
- 在 的二进制表示中,处于 位置()的数字是 当且仅当在 和 的二进制表示中恰好有一个在 位置的数字为 ,否则该位置数字为 。
例如,(二进制表示:)。
另外,对于长度为 的序列 ,其中位数是在将 按升序排序后得到的序列 中位于 位置处的数值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length : .
Find the maximum value that can be obtained as the median of the length- sequence $(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})$ by rearranging the elements of the sequence .
Here, represents bitwise exclusive OR.
What is bitwise exclusive OR? The bitwise exclusive OR of non-negative integers and , denoted as , is defined as follows:
- The number at the position () in the binary representation of is if and only if exactly one of the numbers at the position in the binary representation of and is , and it is otherwise.
For example, (in binary notation: ).
Also, for a sequence of length , the median of is the value at the -th position of the sequence obtained by sorting in ascending order.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
4 0 0 11 2 7 9 5
Sample Output 1
14
By rearranging as , we get $(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) = (5, 14, 15, 2)$, and the median of this sequence is .
It is impossible to rearrange so that the median of $(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8)$ is or greater, so we print .
Sample Input 2
1
998244353 1000000007
Sample Output 2
1755654
Sample Input 3
5
1 2 4 8 16 32 64 128 256 512
Sample Output 3
192
update @ 2024/3/10 08:35:05