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;
}
本文介绍了一个关于异或运算的编程问题,通过对一个非负整数序列进行操作,定义了一个函数来改变序列中某个元素的值,并计算修改前后序列中两两元素之和再进行异或运算的结果。
586

被折叠的 条评论
为什么被折叠?



