Xenia and Bit Operations(线段树单点更新)
2 seconds
256 megabytes
standard input
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 sequencea1 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 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.
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.
Print m integers — the i-th integer denotes value v for sequence a after the i-th query.
#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(线段树单点更新)的更多相关文章
- HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1166 敌兵布阵(线段树单点更新)
敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...
- poj 2892---Tunnel Warfare(线段树单点更新、区间合并)
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...
- HDU 1166 敌兵布阵(线段树单点更新,板子题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)
Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10575 Accepted: 5489 Descrip ...
- HDU 1166 敌兵布阵(线段树单点更新,区间查询)
描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- HDUOJ----1166敌兵布阵(线段树单点更新)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
随机推荐
- atitit.信息安全的控制总结o7
atitit.信息安全的控制总结o7 1. 信息安全覆盖很多的内容: 1 2. #内部人员导致的安全风险 1 3. #对敏感的数据进行透明的加密 2 4. #安全防护 2 5. #通过数据安全域保护关 ...
- PHP类与面向对象(二)
构造函数和析构函数 构造函数PHP 5 允行开发者在一个类中定义一个方法作为构造函数.具有构造函数的类会在每次创建新对象时先调用此方法,所以非常适合在使用对象之前做一些初始化工作.如果子类中定义了构造 ...
- 3D touch 静态、动态设置及进入APP的跳转方式
申明Quick Action有两种方式:静态和动态 静态是在info.plist文件中申明,动态则是在代码中注册,系统支持两者同时存在. -系统限制每个app最多显示4个快捷图标,包括静态和动态 静态 ...
- CentOS7安装mysql数据库
安装完Centos7,迫不急待的想安装mysql数据库,却没想到走了很多弯路,后来经过查资料,才知道了在Centos7中用MariaDB代替了mysql数据库. 准确来说,本文的标题有点误导的意思,本 ...
- redolog文件头简单探究
先切换: SQL> select group#,status from v$log; GROUP# STATUS---------- ---------------- 1 INA ...
- 【Android】wifi开发
WIFI就是一种无线联网技术,常见的是使用无线路由器.那么在这个无线路由器的信号覆盖的范围内都可以采用WIFI连接的方式进行联网.如果无线路由器连接了一个ADSL线路或其他的联网线路,则又被称为“热点 ...
- Android UI系列-----Dialog对话框
您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...
- Gradle 构建 android 应用常见问题解决指南
前言 android gradle 插件已经发展到0.5.7,同时gradle 本身也到了1.8,相比两个月前,android gradle 更快,更完善,也更好用了,为了让各位androider 早 ...
- pip 安装psycopg的错误
psycopg包安装有点问题,特别是在windows下,pip从requirements.txt批量安装总是出错,发现是这个包的问题. 这里需要用easy_install来装,因为gfw的问题,最好下 ...
- css/js在线压缩工具
http://tool.css-js.com/ 在进行前端的时候,可以参考百度性能监控中心给出的意见: http://developer.baidu.com/apm/index