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 ...
随机推荐
- verilog 奇数分频设计
module tw(clk,k_or,k1,k2); input clk; output k_or,k1,k2; reg [2:0] c1,c2; reg m1,m2; initial begin c ...
- matlab求距一个数最近的奇(偶)数
int_a = floor(a);minEven = int_a+mod(int_a,2); %最近偶数minOdd = int_a+1-mod(int_a,2); %最近奇数
- win7 系统如何设置快速启动栏
a.在任务栏上右键 -> 工具栏 -> 新建工具栏 -> 跳出选择文件夹对话框,在文件夹里面(光标山洞处)输入这个路径,然后按回车: %userprofile%\AppData\Ro ...
- org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actua ...
- 关于arguments对象以及函数的柯里化;
1.arguments对象 Arguments是个类似数组但不是数组的对象,说他类似数组是因为其具备数组相同的访问性质及方式,能够由arguments[n]来访问对应的单个参数的值,并拥有数组长度属性 ...
- 从C中变化过来的各种语言的printf输出格式
在c.php和shell中经常可以碰到printf的使用,特别是在php中printf的相关变种有好几个:print.printf.sprintf.vprintf.vsprintf 在这些语言 ...
- android 系统应用在运行时被卸载
android 系统应用在运行时被rm 掉了,是否还会运行? 环境:root,且开机运行 经过试验,apk本身是在 /system/app 目录下面,且apk已经运行了,这个时候直接 rm /syst ...
- HDU 5693 D Game 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5693 题解: 一种朴实的想法是枚举选择可以删除的两个或三个数(其他的大于三的数都能凑成2和3的和), ...
- foxmail收发gmail彻底失败
周一一上班,发现gmail无法收取邮件,刚开始以为网络不稳定,后来经过百度发现原因是 gmail邮箱也被屏蔽了. 虽然可以FQ,保证gmail邮箱暂时使用,但是不可否认,在当前的形势下, ...
- 【CentOS】Eclipse中svn插件使用
目录: 1.安装 2.使用 3.错误 1.安装 svn插件地址: Subclipse 1.6.x Update Site - http://subclipse.tigris.org/update_1. ...