Codeforces Round #197 (Div. 2) : D
这题也是一个线段树的水题;
不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。
最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。
以后比赛的时候不喝啤酒了,再也不喝了。。。。
贴上代码:
#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的更多相关文章
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #197 (Div. 2) : E
看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...
- [置顶] Codeforces Round #197 (Div. 2)(完全)
http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...
- Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)
A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...
- Codeforces Round #197 (Div. 2)
A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...
- Codeforces Round #197 (Div. 2) C,D两题
开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...
- Codeforces Round #197 (Div. 2) : C
哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...
- Codeforces Round #197 (Div. 2) : B
也是水题一个,不过稍微要细心点.... 贴代码: #include<iostream> using namespace std; long long n,m; ; int main() { ...
- Codeforces Round #197 (Div. 2) : A
水题一个: 直接贴代码: #include<cstdio> #include<algorithm> #include<cstring> using namespac ...
随机推荐
- 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
本文主要是想和大家探讨技术,让大家学会Cookie的使用,切勿做违法之事! 很多Android初学者在刚开始学习的时候,或多或少都想自己搞个应用出来,把自己学的十八般武艺全都用在这个APP上,其实这个 ...
- ArcGIS中文件共享锁定数据溢出 这个方法不行,建议用gdb,不要用mdb
ArcGIS中文件共享锁定数据溢出 (2011-11-24 15:52:41) 转载▼ 标签: 杂谈 分类: GIS 文件共享锁定数溢出.(Error 3052)1. Access数据库,同时操作大量 ...
- Beyond REST: How to build a HATEOAS API in Java with Spring MVC, Jersey (JAX-RS) and VRaptor
http://zeroturnaround.com/rebellabs/beyond-rest-how-to-build-a-hateoas-api-in-java-with-spring-mvc-j ...
- c语言,strchr(),查找字符串中第一次字符出现的位置
int main(void) { char string[15]; char *ptr, c = 's'; strcpy(string, "This is a string"); ...
- 11.14 noip模拟试题
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer ...
- uboot源码解析
实例:1.3.4版本at91sam系列 GPIO部分: 一.初始化: include\asm-arm\arch-at91sam9\gpio.h 1.同一引脚的复用设置 2.输入输出初始化寄存器 3.得 ...
- ASP.NET MVC 使用Echarts
Echarts官网 页面配置: <!DOCTYPE html> <html> <head> <meta name="viewport" c ...
- A swift Tour(2) Control Flow
Control Flow 用 if 和 switch 来做条件语句,并且用for-in,for,while,和do-while做循环,条件和循环的括号是可以不写的,但是body外面的括号是必须写的 l ...
- SqlServer Change Data Capture(CDC)数据变更捕获
最近在使用SqlServer2008r2数据库做系统的时候,在某些重要的.经常涉及到修改的表上,想加上一些恢复机制,一开始想找找看看有没有类似Oracle数据库闪回那样的功能,后来发现CDC的功能可以 ...
- centos 6.4 安装firefox使用的flashplayer插件
1.centos安装完后居然没flash-plugin,去官网下载居然告诉已经安装了,可是firefox又的确放不出来flash视频. 2.google一下,去官网下载个tar.gz格式文件.把lib ...