Pagini recente » Cod sursa (job #763219) | Cod sursa (job #2094000) | Cod sursa (job #1518090) | Cod sursa (job #2026935) | Cod sursa (job #1875359)
#include <cstdio>
#include <vector>
using namespace std;
vector<int>pty;
const int nmax=200023;
struct trie
{
int fiu[2];
int ct;
}tr[600023];
int ap[nmax],ps,nt=1;
void add_to_trie(int val)
{
int nod=1;
for(int i=30;i>=0;--i)
{
int fi=0;
if(val&(1<<i)) fi=1;
if(tr[nod].fiu[fi]==0)
{
if(pty.empty()) tr[nod].fiu[fi]=++nt;
else
{
tr[nod].fiu[fi]=pty.back();
pty.pop_back();
}
}
nod=tr[nod].fiu[fi];
tr[nod].ct++;
}
}
void rem_from_trie(int val)
{
int nod=1;
for(int i=30;i>=0;--i)
{
int fi=0;
if(val&(1<<i)) fi=1;
int tmp=nod;
nod=tr[nod].fiu[fi];
tr[nod].ct--;
if(tr[nod].ct==0)
{
tr[tmp].fiu[fi]=0;
pty.push_back(nod);
}
}
}
int query(int x,int k)
{
int sum=0,nod=1;
for(int i=30;i>=0;--i)
{
int fi1=0,fi2=0,fi=0;
if(k&(1<<i)) fi1=1;
if(x&(1<<i)) fi2=1;
// printf("%d %d\n",fi1,fi2);
fi=(fi1^fi2);
if(fi1==1) sum+=(tr[tr[nod].fiu[fi2]].ct);
nod=tr[nod].fiu[fi];
}
// printf("\n");
return sum;
}
int main()
{
freopen ("luffxor.in","r",stdin);
freopen ("luffxor.out","w",stdout);
int m;
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
int tip,x;
scanf("%d%d",&tip,&x);
if(tip==0)
{
ap[++ps]=x;
add_to_trie(x);
}
else if(tip==1) rem_from_trie(ap[x]);
else
{
int k;
scanf("%d",&k);
printf("%d\n",query(x,k));
}
}
}