cf339d Xenia and Bit Operations
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.
Namely, it takes several iterations to calculate value v. At the first iteration, Xenia writes a new sequencea1 or a2, a3 or a4, ..., a2n - 1 or a2n, consisting of 2n - 1 elements. In other words, she writes down the bit-wise OR of adjacent elements of sequence a. At the second iteration, Xenia writes the bitwise exclusive OR of adjacent elements of the sequence obtained after the first iteration. At the third iteration Xenia writes the bitwise OR of the adjacent elements of the sequence obtained after the second iteration. And so on; the operations of bitwise exclusive OR and bitwise OR alternate. In the end, she obtains a sequence consisting of one element, and that element is v.
Let's consider an example. Suppose that sequence a = (1, 2, 3, 4). Then let's write down all the transformations (1, 2, 3, 4) → (1 or 2 = 3, 3 or 4 = 7) → (3 xor 7 = 4). The result is v = 4.
You are given Xenia's initial sequence. But to calculate value v for a given sequence would be too easy, so you are given additional mqueries. Each query is a pair of integers p, b. Query p, b means that you need to perform the assignment ap = b. After each query, you need to print the new value v for the new sequence a.
Input
The first line contains two integers n and m(1 ≤ n ≤ 17, 1 ≤ m ≤ 105). The next line contains 2n integers a1, a2, ..., a2n(0 ≤ ai < 230). Each of the next m lines contains queries. The i-th line contains integers pi, bi(1 ≤ pi ≤ 2n, 0 ≤ bi < 230) — the i-th query.
Output
Print m integers — the i-th integer denotes value v for sequence a after the i-th query.
Sample Input
2 4
1 6 3 5
1 4
3 4
1 2
1 2
1
3
3
3
Hint
For more information on the bit operations, you can follow this link: http://en.wikipedia.org/wiki/Bitwise_operation
很基础的线段树
#include<iostream>
#include<stdio.h>
using namespace std;
const int maxx = <<;
int num[maxx];
int ans[maxx<<];
void build(int l,int r,int rt,int op)
{
if(l==r)
{
ans[rt]=num[l];
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<,-op);
build(mid+,r,rt<<|,-op);
if(op==) ans[rt]=ans[rt<<]|ans[rt<<|];
else ans[rt]=ans[rt<<]^ans[rt<<|];
}
void update(int l,int r,int rt,int index,int value,int op)
{
if(l==r&&l==index)
{
ans[rt]=value;
return;
}
int mid=(l+r)>>;
if(mid<index)
{
update(mid+,r,(rt<<|),index,value,-op);
}
else
{
update(l,mid,rt<<,index,value,-op);
}
if(op==) ans[rt]=ans[rt<<]|ans[rt<<|];
else ans[rt]=ans[rt<<]^ans[rt<<|];
}
int main()
{
//cout<<maxx+1<<endl;
int n,m;
scanf("%d%d",&n,&m);
int sum=<<n;
for(int i=;i<=sum;i++)
scanf("%d",&num[i]);
build(,sum,,n%);
for(int i=;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
update(,sum,,a,b,n%);
printf("%d\n",ans[]);
}
return ;
}
cf339d Xenia and Bit Operations的更多相关文章
- [codeforces 339]D. Xenia and Bit Operations
[codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...
- Xenia and Bit Operations(线段树单点更新)
Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- codeforces 339C Xenia and Bit Operations(线段树水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Bit Operations Xenia the beginn ...
- 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 ...
- Xenia and Bit Operations CodeForces - 339D
Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...
- [线段树]Codeforces 339D Xenia and Bit Operations
Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- 【Codeforces 339】Xenia and Bit Operations
Codeforces 339 D 题意:给定\(2^n\)个数字,现在把它们进行如下操作: 相邻的两个数取\(or\) 相邻的两个数取\(xor\) 以此类推,直到剩下一个数. 问每次修改一个数字, ...
随机推荐
- FishEye
- 初始小R-安装启动与测试
非常感谢<深入浅出数据分析>这本书让我有幸认识了R,多多少少的弥补了我心里对R语言.R分析.R工具的模糊认知,下面我们就来体验一下R语言的魅力吧!GO! 一:下载R R官方地址:http: ...
- [Grunt] Concatenating Your Javascript with grunt-contrib-concat
Combine serval javascript files together. For angular project, make sure you add angular.min.js firs ...
- Linux下双物理网卡设置成虚拟网卡
为了提供网络的高可用我们须要将多块网卡绑定设置成一块虚拟的网卡对外提供服务,这样能够防止一块网卡损坏或者防止网线连接故障造成的连接中断. 以下我们使用eth0与eth1来虚拟成为bond0为例:--- ...
- 换掉Tomcat默认图标
将<Tomcat_home>下的/webapps/ROOT的favicon.ico替换成你自己的图标,名还得是这个名. 然后清除浏览器缓冲,webapp默认的小猫图标就被换掉了. 效果如下 ...
- android源代码在线阅读
http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/
- mysql基础知识之-数据库的创建、查看等常用操作
命令创建mysql数据库: 先启动mysql数据库,连接数据库: mysql -uroot -p123456 (语法:mysql -u登录名 -p密码) 创建表: create dat ...
- PHP XML Parser函数
PHP XML Parser 函数 PHP XML Parser 简介 XML 函数允许您解析 XML 文档,但无法对其进行验证. XML 是一种用于标准结构化文档交换的数据格式.您可以在我们的 XM ...
- Be Happy.——我的ACM退役贴
一个月的忙碌后,最终能静下心来写一些什么. 该结束的最终都要结束了.考试,课程设计,所剩寥寥无几的大学时光,ACM. 看过不少大牛的退役贴,自嘲成银牌狗铜牌狗.写一写碎碎念,大抵如此,每一个人都无法落 ...
- 关于Csdn水区被占据一事 (2015-08-01)
例如以下图所看到的 水区被占据 ,假设发贴机不仅仅在水区发贴.也在其他版块也发贴,将不堪设想啊各位. 如今非常多站点也经历过被 注冊机,发贴机,乱炸,是非常可恨的事.可是您想想.为什么注冊机.发贴机会 ...