#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int N=100005,K=31;
int n,a[N];
int base[K+5];
ll ans;
int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(n);
for (int i=1;i<=n;i++) read(a[i]),ans+=a[i];
sort(a+1,a+n+1,greater<int>());
for (int i=1;i<=n;i++)
{
int tem=a[i];
for (int p=K;~p;p--)
if (a[i]>>p&1)
{
if (!base[p]){
base[p]=i; break;
}
else
a[i]^=a[base[p]];
}
if (a[i]) ans-=tem;
}
printf("%lld\n",ans);
return 0;
}
[高斯消元 线性基 贪心 拟阵] BZOJ 3105 [cqoi2013]新Nim游戏
最新推荐文章于 2019-02-25 21:56:00 发布