CF339D.Xenia and Bit Operations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Xenia the beginner programmer has a sequence aa , consisting of 2n2^{n} non-negative integers: a1,a2,...,a2na_{1},a_{2},...,a_{2^{n}} . Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value vv for aa .

Namely, it takes several iterations to calculate value vv . At the first iteration, Xenia writes a new sequence a1 or a2,a3 or a4,...,a2n1 or a2na_{1} or a_{2},a_{3} or a_{4},...,a_{2^{n}-1} or a_{2^{n}} , consisting of 2n12^{n-1} elements. In other words, she writes down the bit-wise OR of adjacent elements of sequence aa . 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 vv .

Let's consider an example. Suppose that sequence a=(1,2,3,4)a=(1,2,3,4) . Then let's write down all the transformations (1,2,3,4)(1,2,3,4) (1 or 2=3,3 or 4=7)(1 or 2=3,3 or 4=7) (3 xor 7=4)(3 xor 7=4) . The result is v=4v=4 .

You are given Xenia's initial sequence. But to calculate value vv for a given sequence would be too easy, so you are given additional mm queries. Each query is a pair of integers p,bp,b . Query p,bp,b means that you need to perform the assignment ap=ba_{p}=b . After each query, you need to print the new value vv for the new sequence aa .
初学编程的 Xenia 有一个由 2n2^{n} 个非负整数组成的序列 a : a1,a2,...,a2na_{1},a_{2},...,a_{2^{n}} 。Xenia 目前正在学习位操作。为了更好地理解它们的工作原理,Xenia 决定为 a 计算一些值 v 。

也就是说,计算值 v 需要多次迭代。在第一次迭代中,秋莎写下了一个由 2n12^{n - 1} 个元素组成的新序列 a1 or a2,a3 or a4,...,a2n1 or a2na_{1} or a_{2},a_{3} or a_{4},...,a_{2^{n}-1} or a_{2^{n}} 。换句话说,她写下了序列 a 中相邻元素的比特异或。在第二次迭代中,秋莎写下了第一次迭代后得到的序列中相邻元素的位向排他性OR。在第三次迭代中,Xenia 写入第二次迭代后得到的序列中相邻元素的位操作 OR。以此类推,位排序 OR 和位 OR 的操作交替进行。最后,她得到了一个由一个元素组成的序列,这个元素就是 v 。

让我们来看一个例子。假设序列为 a = (1, 2, 3, 4) 。那么让我们写下所有的变换 (1, 2, 3, 4)  →  (1 or 2 = 3, 3 or 4 = 7)  →  (3 xor 7 = 4) .结果是 v = 4 。

你得到了秋莎的初始序列。但是要计算出给定序列的值 v 太简单了,所以我们又给出了额外的 m 个查询。每个查询都是一对整数 p, b 。查询 p, b 意味着需要执行赋值 ap=ba_p = b 。每次查询后,都需要打印新序列 a 的新值 v 。

输入格式

The first line contains two integers nn and mm (1<=n<=17,1<=m<=105)(1<=n<=17,1<=m<=10^{5}) . The next line contains 2n2^{n} integers a1,a2,...,a2na_{1},a_{2},...,a_{2^{n}} (0<=a_{i}<2^{30}) . Each of the next mm lines contains queries. The ii -th line contains integers pi,bip_{i},b_{i} (1<=p_{i}<=2^{n},0<=b_{i}<2^{30}) — the ii -th query.
输入
第一行包含两个整数 n 和 m 。 (1<=n<=17,1<=m<=105)(1<=n<=17,1<=m<=10^{5}) .下一行包含 2n 个整数 a1,a2,...,a2na_{1},a_{2},...,a_{2^{n}} (0<=ai<230)(0<=a_{i}\lt2^{30}) .接下来的每行 m 都包含查询。第 i 行包含整数 pi, bi 。 (1<=pi<=2n,0<=bi<230)(1<=p_{i}<=2^{n},0<=b_{i}\lt2^{30}) - 第 i 次查询。

输出格式

Print mm integers — the ii -th integer denotes value vv for sequence aa after the ii -th query.
输出
打印 m 个整数--第 i 个整数表示第 i 次查询后序列 a 的值 v 。

输入输出样例

  • 输入#1

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

    输出#1

    1
    3
    3
    3
    

说明/提示

For more information on the bit operations, you can follow this link: http://en.wikipedia.org/wiki/Bitwise_operation
注意
有关位操作的更多信息,请访问此链接:http://en.wikipedia.org/wiki/Bitwise_operation

首页