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 ...
随机推荐
- 嵌入式中的 *(volatile unsigned int *)0x500 解释
C语言中*(volatile unsigned int *)0x500的解释: 如下: (unsigned int *)0x500:将地址0x500强制转化为int型指针*(unsigned int ...
- Linux/Android 系统怎么修改mac地址
使用 busybox ifconfig eth0 hw ether AA:BB:CC:DD:EE 可以修改, 但是每次重启都会改回原来的. 所以要修改 /etc/init.mini210.sh (可能 ...
- Java使用FileLock实现Java进程互斥锁
原理:JDK的nio包中FileLock实现类似Linux fcntl的文件锁, 可使文件被进程互斥访问. 借助此功能, 可以实现强大的Java进程互斥锁, 从而在应用层面保证同一时间只有惟一的Ja ...
- NPOI导出word,以及对table的一些设置
参考网址:http://www.aiuxian.com/article/p-1970779.html NPOI版本:2.1.3.1 最终效果图: 代码: /// <summary> /// ...
- 用时间复杂度为n的方法找出水王
一.题目 三人行设计了一个灌水论坛.信息学院的学生都喜欢在上面交流灌水,传说在论坛上有一个“水王”,他不但喜欢发帖,还会回复其他ID发的每个帖子.坊间风闻该“水王”发帖 数目超过了帖子数目 ...
- JS 面向对象之继承 -- 原型链
ECMAScript只支持实现继承,其实现继承主要是靠原型链来实现. 原型链的基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法. 简单回顾下构造函数.原型和实例的关系: 每个构造函数都有 ...
- Java下Web MVC的领跑者:SpringMVC
比较常用的MVC框架有Struts 和 SpringMVC. Struts 是Java Web MVC框架中曾经不争的王者.经过长达九年的发展,Struts占有了MVC框架中最大的市场份额.但是Str ...
- IT服务系统组成
软件+硬件+数据 + 运维人员 = IT服务系统 车 司机 乘客 修车 = 车模式 效率 系统 用户 业务 运维 = 信息化 效率 如果司机不会开车,没有人会修车就不会有车轮上的世界 同样没有人会运维 ...
- Careercup - Google面试题 - 6283958983589888
2014-05-06 11:31 题目链接 原题: Find the k-th Smallest Element in Two Sorted Arrays. I followed the algori ...
- android sdk manager无法更新(2014-11-6测试OK)--自己收藏用
问题描述: Android SDK Manager 无法下载更新,或者更新速度超慢,或者待安装包列表不显示. 解决方法: 第一,我们先修改下hosts文件.该文件的位置在系统盘(一般为C盘), ...