RT,应该是树上下标的问题,把函数里 p=0 换成 1 然后 tot 初始值赋成 1 就过了。不知道为什么
#include <bits/stdc++.h>
#define rint register int
#define int long long
#define endl '\n'
using namespace std;
const int N = 5e5 + 5;
const int M = 3e7 + 5;
int T, n, m;
int a[N], b[N];
int ch[M][2], cnt[M], tot;
void insert(int x, int k)
{
int p = 0;
for (rint i = 30; i >= 0; i--)
{
int t = x >> i & 1;
if (k >> i & 1)
{
if (!ch[p][t]) ch[p][t] = ++tot;
if (!ch[p][!t]) ch[p][!t] = ++tot;
cnt[ch[p][t]]++;
p = ch[p][!t];
}
else
{
if (!ch[p][t]) ch[p][t] = ++tot;
p = ch[p][t];
}
}
cnt[p]++;
}
int query(int x)
{
int p = 0, res = 0;
for (rint i = 30; i >= 0; i--)
{
int t = x >> i & 1;
p = ch[p][t];
res += cnt[p];
}
return res;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> T >> n >> m;
for (rint i = 1; i <= n; i++) cin >> a[i];
for (rint i = 1; i <= n; i++) cin >> b[i];
for (rint i = 1; i <= n; i++) insert(a[i], b[i]);
int last = 0;
for (rint i = 1; i <= m; i++)
{
int k;
cin >> k;
k ^= T * last;
int ans = query(k);
cout << ans << endl;
last = ans;
}
return 0;
}