考察点:Tire 树的运用
其次看到异或运算的最大值应该就要想到tire
最后注意根节点要从1开始。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<math.h>
#define endl '\n'
#define int long long
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
using namespace std;
const int N = 1e5 + 10;
struct tire{
int cnt[N * 33];
int tr[N * 33][2];
int idx = 1;
void insert(int x, int k) {
int p = 1;
for (int i = 30; i >= 0; i--) {
int j = x >> i & 1;
if (!tr[p][j]) tr[p][j] = ++idx;
p = tr[p][j];
cnt[p] += k;
}
}
int query(int x, int h) {
int p = 1;
int res = 0;
for (int i = 30; i >= 0; i--) {
int j_x = x >> i & 1;
int j_h = h >> i & 1;
if(!j_h) {
res += cnt[tr[p][j_x ^ 1]];
p = tr[p][j_x];
}
else {
p = tr[p][j_x ^ 1];
}
}
return res;
}
}T;
void solve() {
int n, hp;
cin >> n >> hp;
for (int i = 0; i < n; i++) {
int op;
cin >> op;
if (!op) {
int x;
cin >> x;
T.insert(x, 1);
}
else if (op == 1) {
int x;
cin >> x;
T.insert(x, -1);
}
else{
int x, h;
cin >> x >> h;
int t = T.query(x, h);
cout << t << endl;
if (!t) hp--;
}
}
cout << hp << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
return 0;
}