HDU 3949 XOR
线性基板子题,注意特判\(0\),开\(long~long\)就好。
#include <cstdio>
#include <cstring>
using namespace std;
#define R register
#define LL long long
#define int long long
const int MAXN=1e4+10;
const int MB=63;
int n,q,cnt,zero;
LL p[MAXN],a[MAXN];
inline void ins(LL x) {
for(R int i=MB;i>=0;i--) {
if(x&(1LL<<i)) {
if(!p[i]) { p[i]=x; return ;}
else x^=p[i];
}
}
if(x==0) zero=1;
}
int d[MAXN],top;
inline void rebuild() {
cnt=0;top=0;
for(R int i=MB;i>=0;i--)
for(R int j=i-1;j>=0;j--)
if(p[i]&(1LL<<j)) p[i]^=p[j];
for(R int i=0;i<=MB;i++) if(p[i]) d[cnt++]=p[i];
}
inline LL kth(int k) {
if(k>=(1LL<<cnt)) return -1;
LL ans=0;
for(R int i=MB;i>=0;i--)
if(k&(1LL<<i)) ans^=d[i];
return ans;
}
inline void solve(int test) {
memset(p,0,sizeof(p));zero=0;
scanf("%lld",&n);
for(R int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(R int i=1;i<=n;i++) ins(a[i]);
rebuild();
scanf("%lld",&q);
printf("Case #%lld:\n",test);
while(q--) {
LL tmp; scanf("%lld",&tmp);
printf("%lld\n",tmp-zero?kth(tmp-zero):0LL);
}
}
signed main() {
int test; scanf("%lld",&test);
for(R int i=1;i<=test;i++) solve(i);
return 0;
}