博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Xenia and Bit Operations CodeForces - 339D
阅读量:5265 次
发布时间:2019-06-14

本文共 3219 字,大约阅读时间需要 10 分钟。

 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define llu unsigned long long#define INF 0x3f3f3f3f#define PI acos(-1.0)const int maxn = 1e7+10;const int mod = 1e9+7;int a[maxn];int date[maxn];int sum[maxn];void push_up(int i){ if(date[i]%2 == 0) sum[i] = sum[i<<1|1] | sum[i<<1]; else sum[i] = sum[i<<1|1] ^ sum[i<<1];}void build(int i,int l,int r){ sum[i] = 0; date[i << 1] = date[i<<1 | 1] = 0; if(l == r) { sum[i] = a[l]; date[i] = -1; return; } int mid = (l+r) >> 1; build(i<<1,l,mid); build((i<<1)|1,mid+1,r); date[i] = date[i<<1]+1; 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)>>1; if(p <= mid) update(l,mid,p,d,i<<1); else update(mid+1,r,p,d,i<<1|1); push_up(i);}int main(){ int n,m; scanf("%d%d",&n,&m); int num=(1<
View Code

 

转载于:https://www.cnblogs.com/smallhester/p/10300550.html

你可能感兴趣的文章
分布式技术追踪 2017年第二十期
查看>>
git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation的解决办法
查看>>
Linux环境变量永久设置方法(zsh)
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
脑袋卡在窗子里
查看>>
ruby 中文字符to_json后乱码(unicode)
查看>>
《大道至简》第六章读后感
查看>>
codeforce 597C-Subsequences(dp+树状数组)
查看>>
[android](学习笔记6)为应用程序添加对话框(1)
查看>>
windows下mongodb安装与使用
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
Python 环境傻瓜式搭建 :Anaconda概述
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>