https://ac.nowcoder.com/acm/contest/57361/C
思维,位运算
#include<bits/stdc++.h>
using namespace std;
int ans[35],b[1000005],f[1000005];
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
for(int i=0;i<=30;i++) ans[i]=-1;
f[0]=0;
for(int i=1;i<=n-1;i++){
cin>>b[i];
f[i]=f[i-1]^b[i];
}
int book=0,num=0;
for(int i=1;i<=n-1;i++){
int temp=b[i],cnt=0;
if(b[i]==0) continue;
while(1){
temp>>=1;
if(temp==0) break;
cnt++;
}
if(ans[cnt]==-1){
ans[cnt]=((f[i-1]>>cnt)&1);
}
else if(ans[cnt]!=((f[i-1]>>cnt)&1)){
book=1;
break;
}
}
k--;
if(book){
cout<<"-1"<<endl;
continue;
}
int a=0;
for(int i=0;i<=29;i++){
if(ans[i]==-1){
ans[i]=k&1;
k>>=1;
}
if(ans[i]==1){
a+=(1<<i);
}
}
if(k){
cout<<"-1"<<endl;
continue;
}
cout<<a<<" ";
for(int i=1;i<=n-1;i++){
cout<<(a^f[i]);
if(i==n-1) cout<<endl;
else cout<<" ";
}
}
}