[题目链接]

https://codeforces.com/problemset/problem/339/D

[算法]

线段树模拟即可

时间复杂度 :O(MN)

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 18
const int MAXS = << MAXN; int n , m;
int a[MAXS]; struct SegmentTree
{
struct Node
{
int l , r;
int value , d;
} Tree[MAXS << ];
inline void update(int index)
{
if (Tree[index].d == ) Tree[index].value = Tree[index << ].value | Tree[index << | ].value;
else Tree[index].value = Tree[index << ].value ^ Tree[index << | ].value;
}
inline void build(int index,int l,int r)
{
Tree[index].l = l;
Tree[index].r = r;
if (l == r)
{
Tree[index].value = a[l];
Tree[index].d = ;
return;
}
int mid = (l + r) >> ;
build(index << ,l,mid);
build(index << | ,mid + ,r);
Tree[index].d = (Tree[index << ].d + ) % ;
update(index);
}
inline void modify(int index,int pos,int val)
{
if (Tree[index].l == Tree[index].r)
{
Tree[index].value = val;
return;
}
int mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= pos) modify(index << ,pos,val);
else modify(index << | ,pos,val);
update(index);
}
inline int query()
{
return Tree[].value;
}
} T; template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ read(n); read(m);
for (int i = ; i <= ( << n); i++) read(a[i]);
T.build(,,( << n));
while (m--)
{
int x , y;
read(x); read(y);
T.modify(,x,y);
printf("%d\n",T.query());
} return ; }

[Codeforces 339D] Xenia and Bit Operations的更多相关文章

  1. [线段树]Codeforces 339D Xenia and Bit Operations

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. CodeForces 339D Xenia and Bit Operations (线段树)

    题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m ...

  3. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  4. Xenia and Bit Operations CodeForces - 339D

    Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...

  5. [codeforces 339]D. Xenia and Bit Operations

    [codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...

  6. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  7. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. cf339d Xenia and Bit Operations

    Xenia and Bit Operations Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Xenia and Bit Operations(线段树单点更新)

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. MYSQL有那些优化?

    版权声明:本文为博主转载文章,原博主地址: https://blog.csdn.net/u013087513/article/details/77899412 MySQL优化三大方向 ① 优化MySQ ...

  2. 理解ZAB协议

    ZAB协议 介绍 1.zab协议是为分布式协调服务zookpeer专门设计的一种支持崩溃恢复的原子广播协议 2.在zookeeper中主要依赖ZAB协议来实现数据一致性,基于该协议zk实现了一种主备模 ...

  3. 得到JavaWeb项目在Tomcat中的运行路径

    获得绝对路径 ··· File file= new File(path); System.out.println(file.getAbsolutePath()); ··· 获得Tomcat路径 这是一 ...

  4. Python爬虫 爬取Web页面图片

    从网页页面上批量下载jpg格式图片,并按照数字递增命名保存到指定的文件夹 Web地址:http://news.weather.com.cn/2017/12/2812347.shtml 打开网页,点击F ...

  5. Balance POJ - 1837 地推

    Gigel has a strange "balance" and he wants to poise it. Actually, the device is different ...

  6. 创建Django项目(三)——站点管理

    2013-08-05 21:01:34|         1.激活管理界面         (1) 修改"mysite\mysite\settings.py"文件,将'django ...

  7. Java函数式接口Function

    Function 提供了一个抽象方法  R apply(T t) 接收一个参数 返回 一个值,还有两个默认方法和一个静态方法 compose 是一个嵌套方法,先执行before.apply() 得到运 ...

  8. Spring Cloud体系实现标签路由

    如果你正在使用Spring Cloud体系,在实际使用过程中正遇到以下问题,可以阅读本文章的内容作为后续你解决这些问题的参考,文章内容不保证无错,请务必仔细思考之后再进行实践. 问题: 1,本地连上开 ...

  9. 记 SpringBoot1.* 转 Springoot2.0 遇到的问题

    1.拦截器问题 到2.0之后在配置文件中写 static-path-pattern: /static/** 已经不起作用(2.0需要在方法中配置) SpringBoot1.*写法 @Configura ...

  10. 18.10.7 POIN 模拟赛

    期望 :80+ +90+40=210+ 实际 :30+90+0=120 链接:https://www.nowcoder.com/acm/contest/175/A来源:牛客网 时间限制:C/C++ 1 ...