【LOJ #6060】「2017 山东一轮集训 Day1 / SDWC2018 Day1」Set(线性基)
显然建出线性基
枚举的每一位做
但是注意线性基实际上每一位是有一个优先级的
而这里优先级是从高到低中为的位大于为的位
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=100006;
ll xorall;
ll bit[65],a[N];
int stk[65],top;
int n;
inline void insert(ll x){
for(int t=1;t<=top;t++){
int i=stk[t];
if(x&(1ll<<i)){
if(!bit[i]){bit[i]=x;return;}
else{
x^=bit[i];
if(!x)return;
}
}
}
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read();
for(int i=1;i<=n;i++){
a[i]=readll(),xorall^=a[i];
}
for(int i=60;~i;i--)if(!(xorall&(1ll<<i)))stk[++top]=i;
for(int i=60;~i;i--)if(xorall&(1ll<<i))stk[++top]=i;
for(int i=1;i<=n;i++)insert(a[i]);
ll ret=0;
for(int i=60;~i;i--){
if(!(xorall&(1ll<<i))&&!(ret&(1ll<<i)))ret^=bit[i];
}
for(int i=60;~i;i--){
if((xorall&(1ll<<i))&&(ret&(1ll<<i)))ret^=bit[i];
}
cout<<ret<<'\n';return 0;
}