从高位到低位建一个01trie
每次对序列异或x
实际上只要把新的x异或上前面的所有x再找就可以了
假如原序列中没有x那就是0
有的话就找一遍
尽量往小的跑 满了的话就再往上
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn= 300000+10;
const int maxm = 10000+10;
int in(int &ret)
{
char c;
int sgn ;
if(c=getchar(),c==EOF)return -1;
while(c!='-'&&(c<'0'||c>'9'))c=getchar();
sgn = (c=='-')?-1:1;
ret = (c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
ret *=sgn;
return 1;
}
int ch[maxn*40][2];
int cnt[maxn*40];
bool bo[maxn];
int tot;
void update(int x,int w,int o)
{
if(w==-1)return;
cnt[o]++;
int now = (x>>w)&1;
if(!ch[o][now])ch[o][now] = ++tot;
update(x,w-1,ch[o][now]);
}
int query(int x,int w,int o)
{
int now = (x>>w)&1;
if(!w)
{
if(ch[o][0^now]==0)return 0;
if(ch[o][1^now]==0)return 1;
}
int idx = ch[o][0^now];
if(idx==0)return 0;
if(cnt[idx]<(1<<w))return query(x,w-1,idx);
if(ch[o][1^now]==0)return 1<<w;
return (1<<w) + query(x,w-1,ch[o][1^now]);
}
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif // LOCAL
int n,m;
sdd(n,m);
r1(i,n)
{
int x;sd(x);
if(bo[x])continue;
bo[x]=1;
update(x,20,0);
}
int x = 0 ;
r1(i,m)
{
int k;sd(k);
x^=k;
int ans;
if(bo[x])ans = query(x,20,0);
else ans = 0;
ansn();
}
return 0;
}