CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A
代码如下:
#include<iostream>
#include<cstdio>
#define lson i<<1
#define rson i<<1|1
#define MAX 140000
#define ll __int64
using namespace std;
ll a[MAX],s;
struct tree
{
int l,r;
ll res;
bool flag;
}T[*MAX];
//奇数OR,偶数XOR
void built(int i,int l,int r,bool f)
{
T[i].l=l;
T[i].r=r;
T[i].flag=f;
if(l==r){
T[i].res=a[l];
return ;
}
int m=(l+r)>>;
built(lson,l,m,!f);
built(rson,m+,r,!f);
if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
else T[i].res=T[lson].res^T[rson].res;
}
void update(int i,int d,ll p)
{
if(T[i].l==d&&T[i].r==d){
T[i].res=p;
return ;
}
int m=(T[i].l+T[i].r)>>;
if(d<=m) update(lson,d,p);
else if(d>m) update(rson,d,p);
if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
else T[i].res=T[lson].res^T[rson].res;
}
int main()
{
int n,m,i,k;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=;i<=(<<n);i++) scanf("%I64d",&a[i]);
built(,,(<<n),n&);
for(i=;i<m;i++){
scanf("%d %I64d",&k,&s);
update(,k,s);
printf("%I64d\n",T[].res);
}
}
return ;
}
CF 197 DIV2 Xenia and Bit Operations 线段树的更多相关文章
- codeforces 339C Xenia and Bit Operations(线段树水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Bit Operations Xenia the beginn ...
- CodeForces 339D Xenia and Bit Operations (线段树)
题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m ...
- [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】
题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...
- CF 552(div 3) E Two Teams 线段树,模拟链表
题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- CF 666E Forensic Examination 【SAM 倍增 线段树合并】
CF 666E Forensic Examination 题意: 给出一个串\(s\)和\(n\)个串\(t_i\),\(q\)次询问,每次询问串\(s\)的子串\(s[p_l:p_r]\)在串\(t ...
- CF #296 (Div. 1) A. Glass Carving 线段树
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
随机推荐
- .net 日期格式化
有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTim ...
- shell 函数
1 shell函数的定义及其调用 shell函数有两种格式: function name { commands } name() { commands } 其中,name为函数名,commands为函 ...
- 邻接矩阵实现Dijkstra算法以及BFS与DFS算法
//============================================================================ // Name : MatrixUDG.c ...
- c++函数内部声明函数,在函数外面实现函数是可以的
这个具体有什么用我也不大清楚,只知道可以这样 #include <iostream> //#include "header1.h" using namespace st ...
- xml基础学习笔记03
继续上篇xml学习笔记,坚持.坚持.再坚持啊.... 本篇主要记录: 35.XML节点的删除与修改 36集.用XML制作RSS订阅源 <?php /* 笔记: 35.XML节点的删除与修改 使用 ...
- Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=14.0
参考地址一:点击这里 参考地址二:点击这里 解决方法: 使用office COM元件,电脑里必须要有相对应的版本,比如 Excel 14.0是对应Excel 2010 Excel 12.0是对应Exc ...
- jQuery 效果 - slideDown() 方法[菜单导航栏常用]
实例 以滑动方式显示隐藏的 <p> 元素: $(".btn2").click(function(){ $("p").slideDown(); }); ...
- Introduction to Financial Management
Recently,i am learning some useful things about financial management by reading <Essentials of Co ...
- GitHub教程--上传项目四步法 GitBash命令行下使用方法
之前就用过GitHub,感觉用GitHub托管自己的代码非常不错.可是之前用的都是窗口化的TortoiseGit,省了很多命令行的操作,但是个人非常喜欢使用命令行,于是,今天就试着用了用GitBash ...
- Java 7 中 NIO.2 的使用——第四节 文件和目录
Files类提供了很多方法用于检查在于你真正实际去操作一个文件或目录.这些方法强烈推荐,也非常有用,也能避免很多异常的发生.例如,一个很好的习惯就是在你试着移动一个文件从一个地方到另一个地方的时候,先 ...