#P17204. 「DLESS-6」XOR and MEX

「DLESS-6」XOR and MEX

Background

The input size of this problem is large. Please use a fast input method.

Problem Description

Given a sequence aa of length nn, let f(a,x)f(a,x) be $\operatorname{mex}(a_1\oplus x,a_2\oplus x,\ldots,a_n\oplus x)^{\dagger}$. Find min⁡x=0∞(x+f(a,x))\min_{x=0}^{\infty}(x+f(a,x)). Here, ⊕\oplus denotes the bitwise XOR operation.


†^\dagger For natural numbers x1,x2…,xnx_1,x_2\ldots,x_n, mex⁡(x1,x2,…,xn)\operatorname{mex}(x_1,x_2,\ldots,x_n) denotes the smallest non-negative integer that does not appear among x1,x2,…,xnx_1,x_2,\ldots,x_n.

Input Format

This problem has multiple test cases. The first line contains a positive integer TT, representing the number of test cases.

For each test case:

  • The first line contains a positive integer nn.
  • The second line contains nn numbers, representing the sequence aa.

Output Format

For each test case, output one line with one number, representing the answer.

3
5
1 4 5 2 6
6
0 1 4 5 2 6
3
0 1 3
0
3
2

Hint

[Sample Explanation]

For the first test case, take x=0x=0, then f(a,0)=mex⁡(1,4,5,2,6)=0f(a,0)=\operatorname{mex}(1,4,5,2,6)=0. Obviously, there cannot be an answer smaller than 00.

For the second test case, take x=1x=1, then f(a,1)=mex⁡(1,0,5,4,3,7)=2f(a,1)=\operatorname{mex}(1,0,5,4,3,7)=2. It can be proven that 33 is the minimum value of x+f(a,x)x+f(a,x).

[Constraints]

For all testdata, it is guaranteed that:

  • 1≤T≤201\le T\le 20;
  • 1≤n≤1061\le n\le 10^6;
  • ∀i∈[1,n],0≤ai<230\forall i\in[1,n],0\le a_i<2^{30}.

The special properties of each test point are as follows:

Test Point ID n≤n\le ai<a_i<
1,21,2 10001000 2102^{10}
3∼63\sim 6 ^ 2302^{30}
7∼107\sim 10 5⋅1045\cdot 10^4 ^
11∼1511\sim 15 3⋅1053\cdot 10^5
16∼2016\sim 20 10610^6

Translated by ChatGPT 5