hdu hdu 5683 zxa and xor

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值