外站题,求条
  • 板块灌水区
  • 楼主zhongjisailuo
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/12/21 16:04
  • 上次更新2024/12/21 17:12:45
查看原帖
外站题,求条
1076915
zhongjisailuo楼主2024/12/21 16:04

上下

#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int c[500005]; 
int lowbit(int x)
{
	return x&-x;
}
void add(int i,int x)
{
	for(;i<=n;i+=lowbit(i))
	{
		c[i]=x;
	}
}
int getsum(int i)
{
	int ans=0;
	for(;i>=1;i-=lowbit(i))
	{
		ans^=c[i];
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		add(i,x);
	}
	while(m--)
	{
		int op,x,y;
		cin>>op>>x>>y;
		if(op==1)
		{
			add(x,y);
		}
		else
		{
			cout<<getsum(y)-getsum(x-1)<<"\n";
 		}
	}
	return 0;		
}
2024/12/21 16:04
加载中...