hdu hdu 5683 zxa and xor
阿新 • • 發佈:2019-02-08
zxa had a great interest in exclusive disjunction(i.e. XOR) recently, therefore he took out a non-negative integer sequence a1,a2,⋯,an of length n.
zxa thought only doing this was too boring, hence a function funct(x,y) defined by him, in which ax would be changed into y irrevocably and then comput
分析:兩次異或同一個數返回原數。先全算一次,在修改!
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100000];
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m,ans=0;
cin>>n>>m;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
ans^=(a[i]+a[j]);
}
}
for(int i=0;i<m;i++)
{
int r,l;
cin >>r>>l;
for(int k=1;k<=n;k++)
{
if(k!=r)
ans^=(a[k]+a[r]),ans^=(a[k]+l);
}
a[r]=l;
cout<<ans<<endl;
}
}
return 0;
}