# acwing 143. 最大异或对

#### 输入样例：

3
1 2 3


#### 输出样例：

3

#include<cstdio>
#include<cmath>
#include<cstring>
const int maxn = 1e5 + 10;
int bit[33 * maxn][2], n, k, a[maxn], t[35];
inline int max(int a, int b)
{return a > b ? a : b;}
void into(int x)
{
int p = 1,pos=0,i=0,tp=x;
memset(t, 0, sizeof t);
while (x)
{
t[p] = x % 2;
x = x / 2;
++p;
}
for (i = 32; i; --i)
{
if(!bit[pos][t[i]])
bit[pos][t[i]] = ++k;
pos = bit[pos][t[i]];
}
}
int find(int x)
{
int pos = 0, maxx = 0, ans[35] = { 0 }, p = 1, v = 0;
memset(t, 0, sizeof t);
while (x)
{
t[p] = x % 2;
x = x / 2;
++p;
}
for (int i = 32; i; --i)
{
if (bit[pos][!t[i]])ans[i] = 1, v = !t[i];
else ans[i] = 0, v = t[i];
pos = bit[pos][v];
}
for (int i = 32; i; --i)
maxx += ans[i] * pow(2, i - 1);
return maxx;
}
int main()
{
int ans = 0;
freopen("C:\\Users\\Towetrlone\\Desktop\\qwq.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]),into(a[i]);
for (int i = 1; i <= n; ++i)
ans = max(ans, find(a[i]));
printf("%d", ans);
return 0;
}

acwing 143. 最大异或对

(0)
(0)