提交时间:2021-12-08 13:54:50
运行 ID: 33867
#include <iostream> #include <cstdio> #include <cstring> using namespace std; struct Node { int son[2]; bool vis; }t[2000010]; int pos = 1; inline int read() { int s=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; } inline void write(int x) { if(x<0){ putchar('-'); x=-x; } if(x>9) write(x/10); putchar(x%10+'0'); } void Add(long long x) { int p = 1,i; t[p].vis = true; for(i = 32;i >= 0;i--) { long long b = (x>>i)&1; if(!t[t[p].son[b]].vis) t[p].son[b] = ++pos; p = t[p].son[b]; t[p].vis = true; } return; } long long Query(long long x) { long long ans = 0,p = 1,i; for(i = 32;i >= 0;i--) { long long b = (x>>i)&1ll; if(t[t[p].son[!b]].vis) { ans = (ans<<1) + !b; p = t[p].son[!b]; } else { p = t[p].son[b]; ans = (ans<<1) + b; } } return ans; } int main() { //freopen("xor.in","r",stdin); //freopen("xor.out","w",stdout); int T,lhn; T = read(); for(lhn = 1;lhn <= T;lhn++) { int n,m,i; long long x; memset(t,0,sizeof(t)); pos = 1; n = read(); m = read(); for(i = 1;i <= n;i++) { x = read(); Add(x); } putchar('C'); putchar('a'); putchar('s'); putchar('e'); putchar(' '); putchar('#'); write(lhn); putchar(':'); putchar((char)10); while(m--) { x = read(); write(Query(x)); putchar((char)10); } } return 0; }