题解
2026-08-04 17:10:50
发布于:浙江
15阅读
0回复
0点赞
其实就是一个树状数组模板题,只要将运算改成^就行
#include<iostream>
#include<vector>
using namespace std;
struct BIT{
int N=1e5+5;
vector<int>tree;
void init(int n){
tree.resize(n+1);
N=n;
}
int lowbit(int x){return x&(-x);}
void update(int x,int v){
while(x<=N){
tree[x]^=v;
x+=lowbit(x);
}
}
int sum(int x){
int ans=tree[x];
while(x>0){
x-=lowbit(x);
ans^=tree[x];
}
return ans;
}
};
const int N=3e5+5;
int n,q,a[N];
BIT c;
int main(){
cin>>n>>q;
c.init(n);
for(int i=1;i<=n;i++){
cin>>a[i];
c.update(i,a[i]);
}
while(q--){
int opt,x,y;
cin>>opt>>x>>y;
if(opt==1){
c.update(x,y);
}else{
int a=c.sum(y),b=c.sum(x-1);
cout<<(a^b)<<"\n";
}
}
return 0;
}
这里空空如也





有帮助,赞一个