https://www.luogu.com.cn/problem/CF706D
const int N = 3e6 + 10;
int trie[N][2], vis[N], idx;
void insert(int x)
{
int p = 0;
for (int i = 31; i >= 0; i--)
{
int u = (x >> i) & 1;
if (!trie[p][u]) trie[p][u] = ++idx;
p = trie[p][u];
vis[p]++;//步骤
}
}
void remove(int x)
{
int p = 0;
for (int i = 31; i >= 0; i--)
{
int u = (x >> i) & 1;
p = trie[p][u];
vis[p]--;//步骤
}
}
ll find(int x)
{
int p = 0;
ll ans = 0;
for (int i = 31; i >= 0; i--)
{
int u = (x >> i) & 1;
if (trie[p][!u] && vis[trie[p][!u]]) ans = ans * 2 + 1, p = trie[p][!u];//步骤
else ans = ans * 2, p = trie[p][u];
}
return ans;
}
void solve()
{
int n;
cin >> n;
insert(0);
while (n--)
{
char c;
int x;
cin >> c >> x;
if (c == '+') insert(x);
else if (c == '-') remove(x);
else cout << find(x) << '\n';
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}