Luo Gu solution to a problem P5514 [[MtOI2019] retribution stay night]

This question is under the guise of questions surface, in fact, look like a little verify :( I'm trying to shift the question on the test surface as stories to read)

In the sample 1 in, 1 XOR XOR. 5 = 2. 6 , in the sample 2 in, . 9 XOR 36 XOR 25 XOR 18 is XOR. 9 XOR 32 = 15 . So, it is easy to get, the answer is all numbers and XOR. (Examples do not believe their child)

So, we got the code:

// luogu-judger-enable-o2
#include <bits/stdc++.h>
#define maxn 1000010
#define ri register int
using namespace std;
inline int read()
{
    int r=0, f=1;
    char c=getchar();
    while((c<'0'||c>'9')&&c!='-')
        c=getchar();
    if(c=='-')
        f=-1, c=getchar();
    while(c<='9'&&c>='0')
        r=r*10+c-'0', c=getchar();
    return r*f;
}
int n, a[maxn];
long long ans;
int main()
{
    n=read();
    a[1]=read();
    ans=a[1];
    for(ri i=2; i<=n; i++)
    {
        a[i]=read();
        ans^=a[i];
    }
    printf("%d", ans);
    return 0;
}

Or, we can prove it simple:

Since this question may be added, or may be different, however, will be reduced or exclusive, but will add increase, but also the minimum value of this question, it is, of course, all the divergence or minimize answer. And because there are different or commutative, so the order does not matter. In this way, we can also launch the conclusions above.

But I may speak no official explanations so detailed, so you read my explanations may go to the official release of the problem solution where to look, there may be more gains.

Link

Guess you like

Origin www.cnblogs.com/SeashellBaylor/p/11516026.html