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

Input
2 4
1 6 3 5
1 4
3 4
1 2
1 2
Output
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的更多相关文章

  1. [codeforces 339]D. Xenia and Bit Operations

    [codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...

  2. Xenia and Bit Operations(线段树单点更新)

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  4. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  5. 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 ...

  6. Xenia and Bit Operations CodeForces - 339D

    Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...

  7. [线段树]Codeforces 339D Xenia and Bit Operations

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  9. 【Codeforces 339】Xenia and Bit Operations

    Codeforces 339 D 题意:给定\(2^n​\)个数字,现在把它们进行如下操作: 相邻的两个数取\(or\) 相邻的两个数取\(xor\) 以此类推,直到剩下一个数. 问每次修改一个数字, ...

随机推荐

  1. TextView子类的常用属性

    TextView常见的子类包括EditText,Button,CheckBox, RadioButton等. 1.EditText EditText继承自TextView,因此TextView所有属性 ...

  2. Unable to lock the administration directory (/var/lib/dpkg/),is another process using it?

    Description:无法获得锁 /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)Unable to lock the ...

  3. (剑指Offer)面试题4:替换空格

    题目: 请实现一个函数,把字符串中的每个空格替换成“%20”,例如输入“We are happy”,则输出“We%20are%20happy”. 思路: 背景: 在网络编程中,如果URL参数中含有特殊 ...

  4. 从主机系统向虚拟机系统里面copy 文件

    从主机系统向虚拟机系统里面copy 文件: 一:请确保你的虚拟机里面安装了 VMTools 1:安装VMTools 2: 进入虚拟机系统里面,如果没有自动运行 VMtool安装程序,请打开我的电脑,手 ...

  5. shareSDK(分享第三方库)的 使用

    首先,下载第三方库,可以去官网下载,官网的地址我忘记了,但下面有一个我之前下的和我写的例子,其实官方的例子也写我们只是告诉大家用时需要把哪些代码复制出来就可以用了. 1.导入如下框架和第三方库 新浪微 ...

  6. 从零开始编写自己的C#框架(25)——网站部署 【转】

    服务器安全部署文档 目录1.     前言.. 3 2.     部署环境.. 3 2.1         服务器环境信息.. 3 3.     磁盘阵列配置.. 4 4.     安装操作系统.. ...

  7. UNIX网络编程读书笔记:recv和send函数

    这两个函数类似于标准的read和write函数,不过需要一个额外的参数. #include <sys/socket.h> ssize_t recv(int sockfd, void *bu ...

  8. Unity Editor Toolbar 编辑器扩展

    http://www.cnblogs.com/zhaoqingqing/p/3812368.html 1.Apply to Prefab [把改动应用到Prefab] if (GUILayout.Bu ...

  9. 算法笔记_150:图论之双连通及桥的应用(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Description In order to get from one of the F (1 <= F <= 5,000) graz ...

  10. android安装应用程序工具类

    /** * 安装APK文件 *@param APK文件 *Version: *author:YangQuanqing */ private void installAPK(File file){ // ...