The problem can be dealt with by simulation. The first thing to understand is that one of the properties of an XOR operation is the same number of different or two times without effect. Open two arrays, the number of the first a in the number of I, and the other B array to remove all the numbers except for the number of I, as the result of the calculation of the problem. The first value of sum is then computed. Each modification J will be a[j] modified, then b[j]^sum, update B[j], in the calculation of b[j]^sum, and then the addition of a B array other than J is updated on the line. This complexity is O (n (n)).
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
int a[20002], b[20002];
int main ()
{
int T;
scanf ("%d", &t);
while (t--) {
memset (A, 0, sizeof (a));
memset (b, 0, sizeof (b));
int n, m, sum = 0;
scanf ("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf ("%d", &a[i]);
}
for (int i = 0; i < n-1; ++i) {
for (int j = i + 1; j < n; ++j) {
B[i] ^= (A[i] + a[j]);
B[J] ^= (A[i] + a[j]);
Sum ^= (A[i] + a[j]);
}
}
for (int i = 0; i < m; ++i) {
int x, y, t = 0;
scanf ("%d%d", &x, &y);
for (int j = 0; J < N; ++j) {
if (j! = x-1) {
T ^= (y + a[j]);
B[J] = b[j] ^ (A[j] + a[x-1]) ^ (A[j] + y);
}
}
sum = sum ^ b[x-1] ^ t;
B[x-1] = t;
A[x-1] = y;
printf ("%d\n", sum);
}
}
return 0;
}
1004 Zxa and XOR