这题也是一个线段树的水题;
不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。
最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。
以后比赛的时候不喝啤酒了,再也不喝了。。。。
贴上代码:
#include<cstdio>
#include<cstring>
#define maxn 262200
using namespace std; struct tree
{
int num;
int l,r;
tree *left,*right;
} tr[maxn];
int nodecount=,a; void update(tree *root,int ok)
{
if(ok)
root->num=(root->left->num)|(root->right->num);
else root->num=(root->left->num)^(root->right->num);
} void build(tree *root,int l,int r,int ok)
{
root->l=l;
root->r=r;
if(root->l==root->r)
{
scanf("%d",&a);
root->num=a;
return;
}
nodecount++;
root->left=tr+nodecount;
nodecount++;
root->right=tr+nodecount;
int mid=(root->l+root->r)/;
build(root->left,l,mid,ok^);
build(root->right,mid+,r,ok^);
update(root,ok);
} void change(tree *root,int i,int p,int ok)
{
if(root->l==i&&root->r==i)
{
root->num=p;
return;
}
int mid=(root->r+root->l)/;
if(i<=mid) change(root->left,i,p,ok^);
else change(root->right,i,p,ok^);
update(root,ok);
} int main()
{
int x,y,n,m,ans=;
scanf("%d%d",&n,&m);
build(tr,,<<n,n&);
for(int i=; i<m; i++)
{
ans=;
scanf("%d%d",&x,&y);
change(tr,x,y,n&);
printf("%d\n",tr[].num);
}
return ;
}