线段树 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 ...
随机推荐
- SSDT Hook实现简单的进程隐藏和保护【转载】
原文链接:http://www.blogfshare.com/ssdthook-hide-protect.html 原文作者:AloneMonkey SSDT Hook实现简单的进程隐藏和保护 Alo ...
- 第7章 使用RAID与LVM磁盘阵列技术
章节简述: 您好,此章节为新增加的知识内容,正在努力的排版完善,预习2016年9月中旬完成,感谢您的支持,QQ群:340829. 7.1 磁盘冗余阵列 1988年由加利福尼亚大学伯克利分校发表的文章 ...
- Linux LAMP环境搭建
什么是LAMP Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了 ...
- centos rm -rf 恢复删除的文件
Linux有时候执行了 rm -rf 等操作误删了文件绝对是一件可怕的事情,好在有一些解决的办法可以临时救急.这时我们就要用到一款叫做extundelete的工具了. 目录[-] 依赖 安装 查找要恢 ...
- Redis学习手册(Sorted-Sets数据类型)
一.概述: Sorted-Sets和Sets类型极为相似,它们都是字符串的集合,都不允许重复的成员出现在一个Set中.它们之间的主要差别是Sorted-Sets中的每一个成员都会有一个分数(score ...
- poj 2421 Constructing Roads 解题报告
题目链接:http://poj.org/problem?id=2421 实际上又是考最小生成树的内容,也是用到kruskal算法.但稍稍有点不同的是,给出一些已连接的边,要在这些边存在的情况下,拓展出 ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- Androidi性能优化之高效使用内存
应用生存期的绝大多数时间都在用于处理内存中的数据 性能主要取决于以下三个因素: a:CPU如何操作特定的数据类型 b: 数据和指令需要占用多少存储空间 c: 数据在内存中的布局 访问内存: 因为访问内 ...
- 设置IIS会话过期时间
打开默认网站----双击ASP--展开会话属性---更改超时时间-
- php 条件查询和多条件查询
条件循环 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...