正解:线性基+贪心
解题报告:
这题其实没什么好写题解的,,,显然贪心一下尽量选魔力大的,不用证明趴挺显然的来着
所以就直接按魔力排个序,插入线性基里面,能插就加个贡献,over
放下代码趴QwQ
(我好像,真的,写得越来越敷衍了TT


#include<bits/stdc++.h> using namespace std; #define il inline #define ll long long #define gc getchar() #define rc register char #define rb register bool #define rp(i,x,y) for(ll i=x;i<=y;++i) #define my(i,x,y) for(ll i=x;i>=y;--i) const ll M=62+10,N=1000+10; ll n,poww[M]={1},as; struct stone{ll num,magic;}ston[N]; struct matrix { ll nod[M]; il bool insert(ll x){my(i,M-10,0)if(x&poww[i]){if(!nod[i])return nod[i]=x,1;x^=nod[i];}return 0;} // il ll mx(){ll ret=0;my(i,M-10,0)ret=max(ret,ret^nod[i]);return ret;} }gg; il ll read() { rc ch=gc;ll x=0;rb y=1; while(ch!='-' && (ch>'9' || ch<'0'))ch=gc; if(ch=='-')ch=gc,y=0; while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc; return y?x:-x; } il bool cmp(stone gd,stone gs){return gd.magic>gs.magic;} int main() { // freopen("4570.in","r",stdin);freopen("4570.out","w",stdout); rp(i,1,M-10)poww[i]=poww[i-1]<<1; n=read();rp(i,1,n)ston[i]=(stone){read(),read()};sort(ston+1,ston+1+n,cmp); rp(i,1,n)if(gg.insert(ston[i].num))as+=ston[i].magic;printf("%lld\n",as); return 0; }