1004 Zxa and XOR

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.