5979: Xenia and Bit Operations

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

Xenia 初学者程序员有一个序列 a,包括2n非负整数:一个a1,a2,...,a2n.Xenia目前正在研究位运算。为了更好地理解它们是如何工作的,Xenia决定为a计算一些值v
也就是说,计算值 v 需要多次迭代。在第一次迭代中,Xenia 编写一个新序列一个a1a2,a34,...,a2n-12n,包括2N-1元素。换句话说,她写下序列 a 的相邻元素的逐位 OR。在第二次迭代中,Xenia 写入第一次迭代后获得的序列的相邻元素的按位独占 OR。在第三次迭代中,Xenia 写入第二次迭代后获得的序列的相邻元素的按位 OR。等等;按位独占 OR 和按位 OR 交替的运算。最后,她得到一个由一个元素组成的序列,该元素是v
让我们考虑一个例子。假设序列 a=(1,2,3,4)。然后让我们写下所有变换 (1,2,3,4) → (1 或 2=3,34=7) → (3xor7=4)。结果是 v=4。
你会得到Xenia的初始序列。但是计算给定序列的值 v 太容易了,因此会为您提供额外的 m 查询。每个查询都是一对整数 pb。查询 pb 表示您需要执行分配一个ap=b.每次查询后,您需要为新序列 a 打印新值 v

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 sequence a1ora2,a3ora4,...,a2n-1ora2n, 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) (1or2=3,3or4=7) (3xor7=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 m queries. 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.
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

输入格式

第一行包含两个整数 n 和 m (1≤n≤17.1≤m≤105).下一行包含2n整数一个a1a2,...,a2n (0≤ai<230).接下来的每一行都包含查询。第 i 行包含整数pibi (1≤pi≤2n0≤bi<230)− 第 i 个查询。

输出格式

打印 m 个整数 −  i 个整数表示第 i 个查询后序列 a 的值 v

Input

2 4

1 6 3 5

1 4

3 4

1 2

1 2

Output

1

3

3

3

 

注意

有关位操作的更多信息,您可以按照以下 link: http://en.wikipedia.org/wiki/Bitwise_operation

输入样例 复制

2 4
1 6 3 5
1 4
3 4
1 2
1 2

输出样例 复制

1
3
3
3

分类标签