Xenia and Bit Operations CodeForces - 339D

Xenia the beginner programmer has a sequence a, consisting of 2nnon-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 sequence a1 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 aafter the i-th query.

Examples

Input
2 4
1 6 3 5
1 4
3 4
1 2
1 2
Output
1
3
3
3

Note

For more information on the bit operations, you can follow this link: http://en.wikipedia.org/wiki/Bitwise_operation

题意:给出一个长度为2^n序列,和几次查询,每次都将其中下标的某值改掉,之后两两或操作,得到2^(n-1)的长度后开始异或,之后在或,直至只有一个数字

题解:线段树的操作,在push_up的时候考虑一下层数是 | 还是 ^ ;

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 1e7+;
const int mod = 1e9+; int a[maxn];
int date[maxn];
int sum[maxn]; void push_up(int i)
{
if(date[i]% == )
sum[i] = sum[i<<|] | sum[i<<];
else
sum[i] = sum[i<<|] ^ sum[i<<];
}
void build(int i,int l,int r)
{
sum[i] = ;
date[i << ] = date[i<< | ] = ;
if(l == r)
{
sum[i] = a[l]; date[i] = -; return;
}
int mid = (l+r) >> ;
build(i<<,l,mid);
build((i<<)|,mid+,r);
date[i] = date[i<<]+;
push_up(i);
} void update(int l,int r,int p,int d,int i)
{
if(l == r)
{
sum[i] = d;
return;
}
int mid = (l+r)>>;
if(p <= mid)
update(l,mid,p,d,i<<);
else
update(mid+,r,p,d,i<<|);
push_up(i);
} int main()
{
int n,m;
scanf("%d%d",&n,&m);
int num=(<<n);
for(int i=;i<=num;i++)
scanf("%d",&a[i]);
date[]=;
build(,,num);
for(int i=;i<=m;i++)
{
int p,b;
scanf("%d%d",&p,&b);
update(,num,p,b,);
printf("%d\n",sum[] );
}
}

Xenia and Bit Operations CodeForces - 339D的更多相关文章

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

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

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

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

  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. cf339d Xenia and Bit Operations

    Xenia and Bit Operations Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

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

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

  8. [Codeforces 339D] Xenia and Bit Operations

    [题目链接] https://codeforces.com/problemset/problem/339/D [算法] 线段树模拟即可 时间复杂度 :O(MN) [代码] #include<bi ...

  9. CodeForces 339D Xenia and Bit Operations (线段树)

    题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m ...

随机推荐

  1. 使用Docx.dll插入图片在Centos 7 上报错:system.DllNotFound:libgdiplus.so

    熬了N天,终于把WORD 文档打开替换.插入图片完好,部署,本机测试没有问题 可是一放到服务器(Centos 7) 就提示下面的错误: 度娘一下: https://www.cnblogs.com/xi ...

  2. linux修改系统时间为北京时间(CentOS)

    删除本地时间 rm -rf /etc/localtime 设置时区为上海 ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 利用date查看 ...

  3. C#对话框-打开和保存对话框(转)

    //打开文件            OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.In ...

  4. 常用CSS3属性整理

    常用CSS3属性整理 文本 文本超出部分折叠 white-space:nowarp; overflow:hidden; text-overflow:ellipsis word-warp 边界换行 no ...

  5. Java static修饰符小记

    首先我们明确一点:java是一个纯面向对象的编程语言,它的每一个文件都视为一个类,当我们创建一个对象的时候,就是在调用一个文件,那么这个时候,这个文件(类)里的一些东西,它是需要通过对象来使用或访问, ...

  6. python 学习之FAQ:文档内容写入报错

    2017.3.29 FAQ 1. 文档内容写入报错 使用with open() as file: 写入文档时,出现'\xa9'特殊字符写入报错,通过print('\xa9')打印输出“©”. > ...

  7. 【Python音乐生成】这是一个超棒的dataset

    http://colinraffel.com/projects/lmd/

  8. X86/X64 函数调用约定

    C 语言有 __cdecl.__stdcall.__fastcall.naked.__pascal. C++ 语言有 __cdecl.__stdcall.__fastcall.naked.__pasc ...

  9. windows xp professional 序列号(密钥)及百度网盘下载地址

    HH7VV-6P3G9-82TWK-QKJJ3-MXR96 https://pan.baidu.com/share/link?uk=4247247642&shareid=500360

  10. 在vue-cli中引入图片不能正常显示

    我们用vue-cli构建项目的时候,图片的地址是后台的,可是在template中item.img放到src中是不能正常显示的为什么? 原因是:url-loader无法解析js动态生成的路径. 解决: ...