#include <iostream>
#include <cstdio>
using namespace std;
int s[2000005][2], cnt, n, m, x, uu, ans, dep[2000005], siz[2000005];
void ins(){
int u=0;
for(int i=19; i>=0; i--){
int t=(x&(1<<i))>0;
if(!s[u][t]) s[u][t] = ++cnt;
u = s[u][t];
}
}
void dfs(int o){
if(o) siz[o] = 1;
if(s[o][0]) dfs(s[o][0]);
if(s[o][1]) dfs(s[o][1]);
siz[o] += siz[s[o][0]] + siz[s[o][1]];
}
void getAns(){
int u=0;
for(int i=19; i>=0; i--){
int t=(x&(1<<i))>0;
if(siz[s[u][t]]!=(1<<(i+1))-1){
ans |= t<<i;
u = s[u][t];
}
else{
ans |= (t^1)<<i;
u = s[u][t^1];
}
}
}
int main(){
cin>>n>>m;
for(int i=1; i<=n; i++){
scanf("%d", &x);
ins();
}
x = 0;
dfs(0);
while(m--){
ans = 0;
scanf("%d", &uu);
x ^= uu;
getAns();
printf("%d\n", ans^x);
}
return 0;
}
转载于:https://www.cnblogs.com/poorpool/p/8443224.html