线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
/*
线段树的单点更新:有一个交叉更新,若rank=1,or;rank=0,xor
详细解释:http://www.xuebuyuan.com/1154895.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define lson l, mid, rt << 1
#define rson mid+1, r, rt << 1 | 1 const int MAXN = << | ;
const int INF = 0x3f3f3f3f;
struct NODE
{
int v, mx, mn, sum;
int rank;
}node[MAXN << ]; void push_up(int rt)
{
if (node[rt<<].rank == )
{
node[rt].rank = ;
node[rt].v = node[rt<<].v | node[rt<<|].v;
}
else
{
node[rt].rank = ;
node[rt].v = node[rt<<].v ^ node[rt<<|].v;
}
} void build(int l, int r, int rt)
{
if (l == r)
{
scanf ("%d", &node[rt].v);
node[rt].rank = ;
return ;
}
int mid = (l + r) >> ;
build (lson);
build (rson); push_up (rt);
} void updata(int p, int b, int l, int r, int rt)
{
if (l == r)
{
node[rt].v = b;
return ;
}
int mid = (l + r) >> ;
if (p <= mid) updata (p, b, lson);
else updata (p, b, rson); push_up (rt);
} int main(void) //Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
{
//freopen ("H.in", "r", stdin); int n, m;
scanf ("%d%d", &n, &m);
build (, <<n, ); int p, b;
for (int i=; i<=m; ++i)
{
scanf ("%d%d", &p, &b);
updata (p, b, , <<n, );
printf ("%d\n", node[].v);
} return ;
}
线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations的更多相关文章
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- [置顶] 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) C,D两题
开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...
- Codeforces Round #197 (Div. 2) : D
这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...
- 维护前面的position+主席树 Codeforces Round #406 (Div. 2) E
http://codeforces.com/contest/787/problem/E 题目大意:给你n块,每个块都有一个颜色,定义一个k,表示在区间[l,r]中最多有k中不同的颜色.另k=1,2,3 ...
- Codeforces Round #197 (Div. 2) : E
看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...
- Codeforces Round #197 (Div. 2)
A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...
随机推荐
- zstu.4189: 逻辑运算(构建 && 前缀表达式入门)
4189: 逻辑运算 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 274 Solved: 42 Description 还记得大学里学过的模电么, ...
- linux 使用 ionice 限制 Xen 虚拟机磁盘 IO
作为 VPS 服务商我们需要保证每个 VPS 公平的使用 host(服务器)的资源,避免某个 VPS 因为程序死循环.挂起.滥用等因素 “拖累” 其他 VPS,如果出现这个情况如何临时限制这个 VPS ...
- Linux 常用软件和服务的配置网站
http://www.linuxidc.com/Linux/2012-11/73862.htm Linux zabbix的安装和配置
- [ruby on rails] 跟我学之(5)显示所有数据
之前的index页,显示的是hello world,现在将其修改为显示我们在rails console里面录入的数据. 1. 修改action 如之前的章节<[ruby on rails] 跟我 ...
- How to Configure Nginx for Optimized Performance
Features Pricing Add-ons Resources | Log in Sign up Guides & Tutorials Web Server Guides Nginx ...
- AWS AutoScaling
origin_from: http://blog.csdn.net/libing_thinking/article/details/48327189 AutoScaling 是 AWS 比较核心的一个 ...
- 在SharePoint 2010 母版页里添加自定义用户控件
在SharePoint 2010 母版页里添加自定义用户控件(译) 使用自定义用户控件的好处: 1.容易部署:2.易于控制显示或隐藏. (在使用的过程中)可能要面对的问题是:如何在用户控件里使用Sha ...
- tomcat启动是报Multiple Contexts have a path of "/XXX"
Eclipse集成了tomcat,启动时报如下异常: Could not publish server configuration for Tomcat v7.0 Server at localhos ...
- FFmpeg Filters Images 参数及效果图
FFmpeg Filters Images 参数及效果图(chm) 下载 ffmpeg filters images 352 si.chm (27.98M) 下载 ffmpeg filters onl ...
- DP:Wooden Sticks(POJ 1065)
摆木棍 题目大意:即使有一堆木棍,给一个特殊机器加工,木棍都有两个属性,一个是l一个是w,当机器启动的时候(加工第一根木棒的时候),需要一分钟,在这以后,设机器加工的上一根木棒的长度是l,质量是w,下 ...