求子序列的最大XOR。
https://www.luogu.org/blog/Marser/solution-p3812 //详细
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define FI first
#define SE second
#define MP make_pair
#define PII pair<int,int>
const int mod = 1e9+7;
const int MX = 1e5+5;
const int LOG = 62;
LL s[55],b[LOG+5],nb[LOG+5],tot;//b为线性基 nb用来求第K小异或值 tot为nb元素个数
bool flag=false;
void init(){ //初始化
tot=0;
flag=false;
memset(b,0,sizeof(b));
memset(nb,0,sizeof(nb));
}
void insertx(LL x){ //插入
for(int i=LOG;i>=0;i--){//从高位不停的找第一个找不到的1
if(x&(1LL<<i)){
if(!b[i]){
b[i]=x;
return;
}
x^=b[i];
}
}
flag=true;
return ;
}
bool OK(LL x){ //验证
if(x==0&&b[0])return 1;
for(int i=LOG;i>=1;i--){
int j=i-1;
if(x&(1<<j)){
x^=b[i];
if(!x)return 1;
}
}
return 0;
}
LL qmax(LL x=0){ //求最大值
LL res=x;
for(int i=LOG;i>=0;i--){
res=max(res,res^b[i]);
}
return res;
}
LL qmin(LL x=0){ //求最小值
LL res=x;
for(int i=0;i<=LOG;i++){
if(b[i])res^=b[i];
}
return res;
}
void rebuild(){ //第K大
for(int i=LOG;i>=0;i--){
if(b[i]==0)continue;
for(int j=i-1;j>=0;j--){
if(b[j]==0)continue;
if(b[i]&(1LL<<j))b[i]^=b[j];
}
}
for(int i=0;i<=LOG;i++){
if(b[i])nb[tot++]=b[i];
}
}
LL kthMax(LL k){
if(flag)k--;
LL res=0;
if(k==0)return 0;
if(k>=(1LL<<tot))return -1;
for(int i=LOG;i>=0;i--){
if(k&(1LL<<i))res^=nb[i];
}
return res;
}
int main(){
int n;cin>>n;
init();
for(int i=1;i<=n;i++)cin>>s[i],insertx(s[i]);
cout<<qmax(0);
return 0;
}