# [Codeforces 817E] Choosing The Commander Trie树

E. Choosing The Commander time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.

Vova managed to build a large army, but forgot about the main person in the army – the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.

Each warrior is represented by his personality — an integer number pi. Each commander has two characteristics — his personality pjand leadership lj (both are integer numbers). Warrior i respects commander j only if  ( is the bitwise excluding OR ofx and y).

Initially Vova’s army is empty. There are three different types of events that can happen with the army:

• pi — one warrior with personality pi joins Vova’s army;
• pi — one warrior with personality pi leaves Vova’s army;
• pi li — Vova tries to hire a commander with personality pi and leadership li.

For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven’t left yet)respect the commander he tries to hire.

Input

The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events.

Then q lines follow. Each line describes the event:

• pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova’s army;
• pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova’s army (it is guaranteed that there is at least one such warrior in Vova’s army by this moment);
• pi li (1 ≤ pi, li ≤ 108) — Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type.

Output

For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.

Example input

```5
1 3
1 4
3 6 3
2 4
3 6 3
```

output

```1
0
```

Note

In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2 < 3, but , and 5 ≥ 3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him.

xor相关，没有什么别的好的性质，于是考虑xor的原始定义——–>按位异或———–>于是可以想到01Trie树.

Code：

``````#include <bits/stdc++.h>
using namespace std;
{int x=0;
char c=getchar();
while (c<'0'||c>'9') {c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x;
}
struct trie
{int s,ch[2];
}t[3000005];
int cnt=1,rt=1;
{int pos=1,i,tg;
t[pos].s++;
for (i=26;i>=0;i--)
{if (x&(1<<i)) {tg=1;}
else {tg=0;}
if (!t[pos].ch[tg])
{t[pos].ch[tg]=++cnt;}
pos=t[pos].ch[tg];
t[pos].s++;
}
return;
}
inline void del(int x)
{int pos=1,i,tg;
t[pos].s--;
for (i=26;i>=0;i--)
{if (x&(1<<i)) {tg=1;}
else {tg=0;}
pos=t[pos].ch[tg];
t[pos].s--;
}
return;
}
{int ans=0,pos=1,i,nt=0,ok;
for (i=26;i>=0;i--)
{if (nt+(1<<i)-1<tar)
{ok=1;nt=(nt+(1<<i));}
else
{ok=0;}
int p=x&(1<<i),tag;
if (p>0) {tag=0;}
else {tag=1;}
if (!ok) {tag^=1;}
else {ans+=t[t[pos].ch[tag^1]].s;}
pos=t[pos].ch[tag];
}
printf ("%d\n",ans);
return;
}
int main (){
int p,q,l,opt;
while (q--)