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. 数据库 DB MySQL 基本操作 CRUD 多表 MD

    操作数据库 创建数据库:create 创建一个名称为mydb1的数据库 create database mydb1; 创建一个使用gbk字符集的mydb2数据库 create database myd ...

  2. React 同构思想

    作者:yangchunwen React比较吸引我的地方在于其客户端-服务端同构特性,服务端-客户端可复用组件,本文来简单介绍下这一架构思想. 出于篇幅原因,本文不会介绍React基础,所以,如果你还 ...

  3. Thinkphp学习笔记5-URL生成U方法

    为了配合所使用的URL模式,我们需要能够动态的根据当前的URL设置生成对应的URL地址,为此,ThinkPHP内置提供了U方法,用于URL的动态生成,可以确保项目在移植过程中不受环境的影响. 定义规则 ...

  4. Thinkphp学习笔记2-

    因为操作方法就是控制器的一个方法,所以遇到有和系统的关键字冲突的方法可能就不能定义了,这个时候我们可以设置操作方法的后缀来解决,例如: 'ACTION_SUFFIX' => 'Action', ...

  5. CSS3-border-radius 属性

    向 div 元素添加圆角边框: div { border:2px solid; border-radius:25px; } IE9+.Firefox 4+.Chrome.Safari 5+ 以及 Op ...

  6. C#控件一览表

    C#控件一览表 .窗体 .常用属性 ()Name属性:用来获取或设置窗体的名称,在应用程序中可通过Name属性来引用窗体. () WindowState属性: 用来获取或设置窗体的窗口状态. 取值有三 ...

  7. Servlet对文件的读写操作

    (1)怎样在serlvet中读取文件的内容 package com.tsinghua; import java.io.*; import javax.servlet.http.*; public cl ...

  8. C#应用视频教程1.1 Socket通信基础

    做Socket通信之前,我们首先要实现几个基本的功能 获取本机IP地址(如果我们要做Socket的服务器,肯定不希望用户每次填写本机IP地址,而是自动获取本机IP地址,这一点我们最好能做的比已有的软件 ...

  9. Could not find RubyGem cocoapods 错误

    之前安装过一次cocoapods 后来,安装octopress,安装过一次较新版的ruby,可能是由于ruby安装,把之前的cocoapods删除了,结果使用,出现如图错误 解决: 重新安装 coco ...

  10. NET设计规范(二) 命名规范

    http://blog.csdn.net/richnaly/article/details/6280294 第2章       命名规范 2.1.   大小写约定 2.1.1.    标识符的大小写规 ...