这题也是一个线段树的水题;

不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。

最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。

以后比赛的时候不喝啤酒了,再也不喝了。。。。

贴上代码:

 #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 ;
}

Codeforces Round #197 (Div. 2) : D的更多相关文章

  1. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  2. Codeforces Round #197 (Div. 2) : E

    看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...

  3. [置顶] Codeforces Round #197 (Div. 2)(完全)

    http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...

  4. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  5. Codeforces Round #197 (Div. 2)

    A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...

  6. Codeforces Round #197 (Div. 2) C,D两题

    开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...

  7. Codeforces Round #197 (Div. 2) : C

    哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...

  8. Codeforces Round #197 (Div. 2) : B

    也是水题一个,不过稍微要细心点.... 贴代码: #include<iostream> using namespace std; long long n,m; ; int main() { ...

  9. Codeforces Round #197 (Div. 2) : A

    水题一个: 直接贴代码: #include<cstdio> #include<algorithm> #include<cstring> using namespac ...

随机推荐

  1. byte数组与对象之间的相互转换

    在进行网络通信时可能需要传输对象,如果用NIO的话,只能用Bytebuffer和channel直接 通过ByteArray*Stream和Object*Stream可以将byte数组和对象进行相互的转 ...

  2. Eclipse错误

    1.java compiler level does not match the version of the installed java project facet 解决:http://blog. ...

  3. elfiner-servlet 2.x已开源!

    通过近一周的努力,elfiner-servlet 2.x基本搞定! 已提交github,开源之!请各位享用~~ 对elfinder不熟悉的请访问:http://elfinder.org 一个很不错的文 ...

  4. Asp.net 上传文件小叙(修改FileUpload显示文字等)

    想要在asp.net网站上上传文件就得用到FileUpload,可是这个控件中“浏览”没法修改,可以使用html中<input type="file" 来解决该问题. 首先页 ...

  5. 那天有个小孩跟我说LINQ(七)转载

    1  LINQ TO XML(代码下载)        准备:新建项目 linq_Ch7控制台程序,新建一个XML文件夹,我们就轻松地学习一下吧          XDocument         ...

  6. linux yum配置

    yum源模版 vi /etc/yum.repos.d/xxx.repo [rhel-server]name=serverbaseurl=file:///media/disk/Serverenabled ...

  7. Oracle 递归函数与等级

    --基数数据1 SELECT ID, mt.materialtypename, mt.parenttypeid FROM material_type mt; 使用递归还是与LEVEL 1 SELECT ...

  8. jjQuery 源码分析1: 整体结构

    目前阅读的是jQuery 1.11.3的源码,有参考nuysoft的资料. 原来比较喜欢在自己的Evernote上做学习基类,并没有在网上写技术博客的习惯,现在开始学习JS的开源代码,想跟大家多交流, ...

  9. (转)Object-C 中各数据类型转换 NSData转NSString,Byte,UIImage

    ,NSData 与 NSString NSData --> NSString NSString *aString = [[NSString alloc] initWithData:adata e ...

  10. IOS 学习笔记 20150314

    Objective--C 类与对象 1 关键字 @interace 类定义 @end 类结束 @implementation 类实现 : 继承 @public 公用 @private 私有 @prot ...