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\) 以此类推,直到剩下一个数. 问每次修改一个数字, ...
随机推荐
- C#视频播放器【转】
1对于视频播放器来说,最重要的功能,莫过于播放视频文件了这就要用到VS自带的控件——Windows Media Player windows media player 将Windows Media P ...
- Minify压缩JS和CSS
Minify把CSS和JS压缩和削减(Minify:去掉空格回车符等),以及把多个CSS,JS文件整合到一个文件里.不要以为你的大带宽没有必要进行这类优化.使用它的理由更重要的是文件合并,而不是压缩, ...
- ItermCF的MR并行实现
ItermCF的MR并行实现 @(Hadoop) ItermCF的基本思想 基于物品相似度的协同过滤推荐的思想大致可分为两部分: 1.计算物与物之前的相似度 2.根据用户的行为历史,给出和历史列表中的 ...
- Transformer中引用iqd作为数据源导入报错TR1907与TR3312
好久没和transform接触了,初次接触就给我送了个大礼,在选择好iqd文件执行最后一步导入的时候,要求我对数据源输入用户名密码,我连续输入了三次用户名和密码,在我十分肯定用户名和密码没错的情况下, ...
- Ubuntu 中/etc/resolv.conf 文件修改丢失的解决方案
方法一 1.需要创建一个文件/etc/resolvconf/resolv.conf.d/tail sudo vi /etc/resolvconf/resolv.conf.d/tail 2.在该文件中写 ...
- C#应用视频教程1.4 实现完整以太网通讯
对于事件和委托机制不够理解的读者可以参考本节提供的委托相关的范例程序,这个是控制台的程序,比较简洁(书店发布一本书的事件注册到某个读者A身上,原理跟前面一小节讲的是一致的,只不过没有通过委托对外发送数 ...
- PHP如何使用免费在线客服插件
1 你可以从以下网址下载http://www.hur.cn/Soft/2011/12448.html 2 解压并放到任意文件夹下 3 在安装之前,先在数据库中创建一个完整的数据库,因为待会儿安装完成之 ...
- CAD设置图层透明显示
在生产制图过程中,图层有利于更好的地理信息的分类,但显示就有些问题了,比如多个面层重叠.通常为了显示多个面重叠区域的特征,我们通常的做法是设置图层填充(符号填充,如地籍处理中经常这样做),或者设置图层 ...
- TCP客户/服务器程序实例——回射服务器
目录 客户/服务器程序源码 POSIX信号处理 POSIX信号语义 处理SIGCHLD信号 处理僵死进程 处理被中断的系统调用 wait和waitpid函数 wait和waitpid函数的区别 网络编 ...
- 查找文本工具grep
许多时候需要从一大堆的命令输出或文本内容中找出一两行关键的内容,例如从系统用户文件中查找某个用户.如果不借助工具,这将是一项非常繁琐的工作,这时可以使用grep工具对内容进行筛选. grep(glob ...