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

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

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

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

贴上代码:

 #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. webbreswer

    为了帮助网友解决"怎么用C#的webBrowser模拟点击页面上的标签"相关的问题,中国学网通过互联网对"怎么用C#的webBrowser模拟点击页面上的标签" ...

  2. SWFObject2.0

    PROBLEM: using % in the height and width(e.g. 100%) with the SWFObject 2.0 (or 2.1) with dynamic pub ...

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

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

  4. PHP中刷新输出缓冲

    http://www.cnblogs.com/mutuan/archive/2012/03/18/2404957.html PHP中刷新输出缓冲buffer是一个内存地址空间,Linux系统默认大小一 ...

  5. swift-01-简述swift与OC区别

    swift语言 Swift是Apple在WWDC2014所发布的一门编程语言,用来撰写OS X和iOS应用程序[1].在设计Swift时.就有意和Objective-C共存,Objective-C是A ...

  6. java新手笔记21 接口

    1.接口 package com.yfs.javase; public interface IDemo1 {//interface 接口 public /*abstract*/ void method ...

  7. js 无刷新分页代码

    /** * 分页事件处理 */function paging(){ $("#firstPage").click(function(){ //首页 var pageNo = getP ...

  8. spring Aop 注解

    个人理解: spring Aop 是什么:面向切面编程,类似于自定义拦截操作,支持拦截之前操作@Before,拦截之后操作@After,拦截环绕操作@Around. 什么情况下使用spring Aop ...

  9. UVA 11464 Even Parity(部分枚举 递推)

    Even Parity We have a grid of size N x N. Each cell of the grid initially contains a zero(0) or a on ...

  10. 【技术·水】浅谈Dism++清理插件开发

    前言 昨天我发布了NCleaner,一款Dism++清理插件(地址:http://bbs.pcbeta.com/viewthread-1692182-1-1.html) 有些人想要我开源NCleane ...