The XOR Largest Path
The XOR Longest Path
question meaning: Given n numbers Ai, ask the maximum value of two numbers A after XOR
Build a trie in flashback, judge the relative position every time you reach p, and start from the relative position if there is one
int n;
int trie[maxn*32+5][2],tot=1;
void inser(LL a){
//trie插入
int p=1;
LL ch=1ll;
for(LL i=32;i>=0;i--){
ch=a>>i&1ll;
if(trie[p][ch]==0)trie[p][ch]=++tot;
p=trie[p][ch];
}
}
LL sear(LL a){
int p=1;
LL ch=1ll,ans=0ll;
for(LL i=32;i>=0;i--){
ch=a>>i&1ll;
if(trie[p][ch^1]){
//相对位置
p=trie[p][ch^1];
ans|=1<<i;
}else{
p=trie[p][ch];
}
}
return ans;
}
LL A[maxn];
int main(){
int n;
sci(n);
LL res=0;
for(int i=1;i<=n;i++){
scl(A[i]);
inser(A[i]);
res=max(res,sear(A[i]));
}
cout<<res<<endl;
return 0;
}