CF2115D 题解
DaiRuiChen007 · · 题解
Problem Link
可以看成从
从高到低确定每一位的取值,首先最高位
然后考虑
所以从
维护
时间复杂度
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e5+5;
ll a[MAXN],b[MAXN],f[MAXN];
bool c[MAXN],g[MAXN];
bool mul(ll x,ll y) { return __builtin_popcountll(x&y)&1; }
void solve() {
int n; ll z=0,S=0;
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i],S^=a[i],f[i]=g[i]=0;
for(int i=1;i<=n;++i) cin>>b[i],a[i]^=b[i];
for(int i=1;i<=n;++i) { char o; cin>>o,c[i]=o-'0'; }
for(int k=59;~k;--k) {
int x=n; ll w=1ll<<k; bool h=0;
for(;;--x) {
for(;x&&!mul(a[x],w);--x);
if(!x) { z|=(mul(S,w)^h)*(1ll<<k); break; }
h^=c[x]^g[x],w^=f[x];
if(!f[x]) { f[x]=w,g[x]=h^c[x],z|=c[x]*(1ll<<k); break; }
}
}
cout<<z<<"\n";
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int _; cin>>_;
while(_--) solve();
return 0;
}