Xenia and Bit Operations
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 fora.

Namely, it takes several iterations to calculate value v. At the first iteration, Xenia writes a new sequenceaor a2, aor 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 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 integersa1, 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.

AC Code:
 #include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cmath>
#define ls rt<<1
#define rs rt<<1|1
using namespace std; struct Node
{
int x;
int res;
}a[<<];
int p[] = {, , , , , , , , , , , , , ,
, , , };
int height; void build_tree(int lef, int rig, int rt)
{
if(rig == lef){
scanf("%d", &a[rt].x);
a[rt].res = a[rt].x;
return ;
}
int mid = (lef + rig) >> ;
build_tree(lef, mid, ls);
build_tree(mid + , rig, rs);
if((height - (int)log2(rt)) & ) a[rt].res = a[rs].res ^ a[ls].res;
else a[rt].res = a[rs].res | a[ls].res;
} void update_tree(int lef, int rig, int rt, int id, int v)
{
if(lef == rig){
a[rt].x = a[rt].res = v;
return ;
}
int mid = (lef + rig) >> ;
if(id > mid) update_tree(mid + , rig, rs, id, v);
else update_tree(lef, mid, ls, id, v);
if((height - (int)log2(rt)) & ) a[rt].res = a[rs].res ^ a[ls].res;
else a[rt].res = a[rs].res | a[ls].res;
} int main()
{
int n, m;
while(scanf("%d %d", &n, &m) != EOF){
height = ceil(log2(p[n] + ));
build_tree(, p[n], );
int b, c;
while(m--){
scanf("%d %d", &b, &c);
update_tree(, p[n], , b, c);
printf("%d\n", a[].res);
}
}
return ;
}

Xenia and Bit Operations(线段树单点更新)的更多相关文章

  1. HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  3. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  4. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  5. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  7. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

  8. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  9. HDUOJ----1166敌兵布阵(线段树单点更新)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  10. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

随机推荐

  1. CI框架笔记

    @update 2016-4-2 13:45:35 一.目录结构 ci_demo ├─myapp 应用主目录 │ ├─autoload.php 自定义的自动加载文件(可选) │ ├─myapp.php ...

  2. eclipse code templates 设置(eclipse注释模版配置)

    文件(Files)注释标签:/** * @Title: ${file_name} * @Package ${package_name} * @Description: ${todo} * Copyri ...

  3. Python包的相对导入时出现错误的解决方法

    在练习Python中package的相对导入时,即 from . import XXX 或者 from .. import XXX 时会遇到这样两个错误: SystemError: Parent mo ...

  4. linux 下查找大于100M的文件(转)

    命令行如下 find . -type f -size +1000000k Linux系统下查找大文件或目录的技巧 当硬盘空间不够时,我们就很关心哪些目录或文件比较大,看看能否干掉一些了,怎么才能知道呢 ...

  5. 解决 01-Jul-2016 10:49:05.875 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [ROOT] registered the JDBC driver [com.mysql.jdbc.D

    01-Jul-2016 10:49:05.875 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoade ...

  6. 【Vegas原创】EXCEL光标所在的行自动变色

      方法: 1,excel中,按Alt+F11,打开VBA编辑界面,双击需要改的工作表名称,将下面代码粘贴到右边框中,即可. 2,代码: Private Sub Worksheet_Selection ...

  7. JAVA利用enum结合testng做数据驱动示例

    数据驱动是做自动化测试中很重要的一部分,数据源的方案也是百花八门了,比如利用外部文件,直接在@DataProvider中写死等等,我们今天介绍一下利用enum来做数据源,先来看一下enum的写法: p ...

  8. brew 出现 git 错误的问题分析

    现象 brew update的时候出现 gitcrash   分析 在brew update 的时候看见有 git gc 的字样,提示有在gc 的动作.到/usr/local/ 目录,直接运行 git ...

  9. windows7实现打印机共享的方法

    windows7实现打印机共享的方法和windows xp差不多,就是在下图当中的设置: 具体方法请参照:http://jingyan.baidu.com/article/6d704a13e00a21 ...

  10. Win10下E3-1231 V3开启Intel虚拟化技术(vt-x)安装HAXM

    硬件配置: 技嘉G1 Sniper B6主板,Intel Xeon E3-1231 V3 CPU.主板和U都支持Intel的虚拟化技术,也在主板的设置界面打开了虚拟化支持,如下图: 使用CPU-V检测 ...