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 ...
随机推荐
- gulp 实践
文档站YDoc 相关注意事项 sass 编译 目录结构 可以直接使用sass编译 ➜ ydoc git:(v2) ✗ sass ./sass/app.scss ./template/source/ap ...
- sizeof strlen strncpy用法总结 结构体实际所占内存大小 以及memset用法
sizeof测类型(数组名除外) strlen测实际长度 strncpy返回指针类型 #include <stdio.h> #include <stdlib.h> #inclu ...
- Modelsim覆盖率
步骤: 1.compile选项 => compile options Covrage setting (或者可以点击选中文件,编辑properties,在coverage中选择要实现的覆盖选 ...
- css所有选择器的详解
----------------------------------------css 选择器---------------------------------------- 1,组合选择器: 1)e ...
- WebUploader——一个页面多个实例上传图片
WebUploader官方例子看的不是很清楚,自己也是费了点劲自己写了一下. 需求:一个单页需要多个实例来上传,一次可上传多张 条件:后台接收C# 首先:引入webuploader webup ...
- html5 video.js 使用及兼容所有浏览器
废话少说,直接开始 一.准备材料 video.js下载: http://www.videojs.com/ 二.代码 引入相关文件:(必须放在文件的开头,也是说一定要放在video标签之前) 贴入htm ...
- oc ios 中文字符串 进行 sha1加密 错误?
我在网上找到了一个oc版加密的工具类,但是加密中文就出现大问题 const char *cstr = [self cStringUsingEncoding:encoding]; NSData *dat ...
- C# 中使用win32函数 GetScrollInfo返回false 返回引用全是零的问题
最近做一个项目要获得ScrollBar的位置,因为.net找不到此类功能,只好用MFC中的函数了,GetScrollPos只返回listview顶部的位置,此时我找到了GetScrollInfo,觉得 ...
- Core模块其他常用知识点[OpenCV 笔记14]
Matx 轻量级的Mat,必须在使用前规定好大小,比如一个2x3的float型的Matx,可以声明为Matx23f Vec Vec是Matx的一个派生类,是一个一维的Matx,跟vector很相似.在 ...
- I/O端口与I/O内存
端口的概念:设备通过系统总线上的接口与CPU相连,接口电路中含有多种寄存器,CPU向设备读写数据实际上是向接口上的寄存器读写数据,这些寄存器称为I/O端口.一个接口通常包含控制端口,数据端口,状态端口 ...