#abc304g. G - Max of Medians

G - Max of Medians

Score : 625625 points

问题描述

给定一个长度为 2N2N 的序列:A=(A1,A2,,A2N)A = (A_1, A_2, \ldots, A_{2N})

通过重新排列序列 AA 中的元素,找出长度为 NN 的序列 $(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})$ 的中位数可能达到的最大值。

此处,\oplus 表示按位异或运算。

什么是按位异或运算?非负整数 AABB 的按位异或(记作 ABA \oplus B)定义如下:

  • ABA \oplus B 的二进制表示中,处于 2k2^k 位置(k0k \geq 0)的数字是 11 当且仅当在 AABB 的二进制表示中恰好有一个在 2k2^k 位置的数字为 11,否则该位置数字为 00

例如,35=63 \oplus 5 = 6(二进制表示:011101=110011 \oplus 101 = 110)。

另外,对于长度为 LL 的序列 BB,其中位数是在将 BB 按升序排序后得到的序列 BB' 中位于 L2+1\lfloor \frac{L}{2} \rfloor + 1 位置处的数值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of length 2N2N: A=(A1,A2,,A2N)A = (A_1, A_2, \ldots, A_{2N}).

Find the maximum value that can be obtained as the median of the length-NN 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 AA.

Here, \oplus represents bitwise exclusive OR.

What is bitwise exclusive OR? The bitwise exclusive OR of non-negative integers AA and BB, denoted as ABA \oplus B, is defined as follows:

  • The number at the 2k2^k position (k0k \geq 0) in the binary representation of ABA \oplus B is 11 if and only if exactly one of the numbers at the 2k2^k position in the binary representation of AA and BB is 11, and it is 00 otherwise.

For example, 35=63 \oplus 5 = 6 (in binary notation: 011101=110011 \oplus 101 = 110).

Also, for a sequence BB of length LL, the median of BB is the value at the L2+1\lfloor \frac{L}{2} \rfloor + 1-th position of the sequence BB' obtained by sorting BB in ascending order.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 0Ai<2300 \leq A_i < 2^{30}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots A2NA_{2N}

Output

Print the answer.

Sample Input 1

4
4 0 0 11 2 7 9 5

Sample Output 1

14

By rearranging AA as (5,0,9,7,11,4,0,2)(5, 0, 9, 7, 11, 4, 0, 2), 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 1414.
It is impossible to rearrange AA 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 1515 or greater, so we print 1414.

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