#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
const int N = 3e6+10;
int idx;
int ne[N][2];
//注意01trie的i的范围是受a[i]值域的影响而非个数
void insert(int t)
{
int p = 0;
for(int i=30;i>=0;--i)
{
int x = t>>i&1;
if(!ne[p][x]) ne[p][x] = ++idx, p = idx;
else p = ne[p][x];
}
}
int query(int t)
{
int p = 0;
int res = 0;
for(int i=30;i>=0;--i)
{
int x = t>>i&1;
if(ne[p][x^1]) res += 1<<i, p = ne[p][x^1];
else p = ne[p][x];
}
return res;
}
void solve()
{
int n;
cin>>n;
int maxn = 0;
for(int i=0;i<n;++i)
{
int t;
cin>>t;
maxn = max(maxn,query(t));
insert(t);
}
cout<<maxn<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin>>T;
while(T--)
{
solve();
}
}
标签:typedef,XOR,01trie,int,P10471,ne,long,vx,return
From: https://www.cnblogs.com/ruoye123456/p/18413487