20303
Hint:
At first, a[1]=20701, a[2]=31075, a[3]=26351a[1]=20701,a[2]=31075,a[3]=26351.
At the first time, a[2]a[2] decrease by 1.
At the second time, a[2]a[2] decrease by 1.
Finally, a[1]=20701, a[2]=31073, a[3]=26351a[1]=20701,a[2]=31073,a[3]=26351. So answer is (20701+1)xor(31073+2)xor(26351+3)=20303(20701+1)xor(31073+2)xor(26351+3)=20303.
模拟一下操作就好了
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 10000005;
const int base = 1e9 + 7;
int T, limit;
int n, q, a[maxn], ft[maxn], nt[maxn];
LL seed;
int rand(int l, int r) {
static long long mo = 1e9 + 7, g = 78125;
return l + ((seed *= g) %= mo) % (r - l + 1);
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d%I64d", &n, &q, &seed);
int sum = rand(q, 10000000);
limit = 0;
for (int i = 1; i <= n; i++)
{
a[i] = rand(0, sum / (n - i + 1));
sum -= a[i];
limit = max(a[i], limit);
}
limit = max(limit, a[rand(1, n)] += sum);
for (int i = 1; i <= max(limit, n); i++) ft[i] = nt[i] = 0;
for (int i = 1; i <= n; i++)
{
if (ft[a[i]])
{
nt[i] = ft[a[i]];
ft[a[i]] = i;
}
else ft[a[i]] = i;
}
int tot = 0;
for (int i = limit, j; i; i--)
{
if (q >= tot) { q = q - tot; limit = i; }
else break;
for (j = ft[i]; j; j = nt[j]) tot++;
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (a[i] >= limit) if (q) { ans ^= (limit + i - 1); q--; }
else ans ^= (limit + i);
else ans ^= a[i] + i;
printf("%d\n", ans);
}
return 0;
}