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 ...
随机推荐
- hdu 1622 Trees on the level
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1622 小白书上的题... #include<algorithm> #include< ...
- Windows Phone8.1 SDK中的新控件
前言 WP8.1对开发者的影响要远大于对用户的影响.这篇博客就来一起看看哪些WP8.0中的控件被移除或替换,这些控件的介绍在MSDN上都非常的详细,所以这里只给出一些简单的介绍,来对比8.1 ...
- Knockout : 实现复杂的web聊天窗体
公司以前一个同事写的这个聊天的窗体,由于是采用了html拼接的方式,外加处理的时候没有合理的划分职责,导致页面js代码量非常庞大(1500行左右).现在这哥们离职了,苦的是我们剩下的人,不多说,我先去 ...
- MongoDB的交互(mongodb/node-mongodb-native)、MongoDB入门
MongoDB 开源,高性能的NoSQL数据库:支持索引.集群.复制和故障转移.各种语言的驱动程序:高伸缩性: NoSQL毕竟还处于发展阶段,也有说它的各种问题的:http://coolshell.c ...
- Swift弹窗
在一个ViewController中使用以下代码: let alertController = UIAlertController(title: "Game Set", messa ...
- iptables规则表
1.iptables规则表 Filter(针对过滤系统):INPUT.FORWARD.OUTPUT NAT(针对地址转换系统):PREROUTING.POSTROUTING.INPUT.OUTPUT ...
- iOS基础问答面试
<简书社区 — Timhbw>iOS基础问答面试题连载(一)-附答案:http://www.jianshu.com/p/1ebf7333808d <简书社区 — Timhbw> ...
- Python 获取学校图书馆OAPC账号对应的身份证号码
import urllib.request import urllib.parse import http.cookiejar import re lib_login = 'http://xxx.ed ...
- Gulp压缩JavaScript代码
因为gulp是自动化工具,所以我们得告诉它,需要怎么做,才能达到我们的目的. 我们首先得新建一个js文件,用来编写我们的需求,以便gulp能按着我们的意愿来执行. 我将这个js文件取名叫gulpfil ...
- mp3 切割
开源的东东很不错,摘了一段好文: 常在听mp3或其他格式音乐的朋友,有时会有特别喜欢的片段,例如副歌的部份会想拿来做手机的铃声.这时候就需要一些处理音效的软体,例如之前提过的 Audacity.其实还 ...