[题目链接]

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. 树莓派 - gpio-led platform driver 控制LED

    树莓派3b板上有两个LED, pwr (power) 和 act (activity).是platform_driver gpio-led驱动. 可以通过设备树和gpio-led来额外控制一个LED. ...

  2. Unix网络编程 — 头文件解析

    1.1. < sys/types.h > primitive system data types(包含很多类型重定义,如pid_t.int8_t等) 1.2. < sys/socke ...

  3. 【03】HTML head 头部分的标签说明 和 手机头部标签说明

    HTML head 头部分的标签.元素有很多,涉及到浏览器对网页的渲染,SEO 等等,而各个浏览器内核以及各个国内浏览器厂商都有些自己的标签元素,这就造成了很多差异性.移动互联网时代,head 头部结 ...

  4. SPOJ-BRCKTS (括号序列,线段树)

    维护括号序列 Replace(i): 将第i个位置的括号反向. Check:测试当前序列是否合法. 题解 将左括号定为1,右括号定为-1,所以只需要满足前缀和序列没有负数即可,即最小值 为正即可,第i ...

  5. MySQL:记录的增删改查、单表查询、约束条件、多表查询、连表、子查询、pymysql模块、MySQL内置功能

    数据操作 插入数据(记录): 用insert: 补充:插入查询结果: insert into 表名(字段1,字段2,...字段n) select (字段1,字段2,...字段n) where ...; ...

  6. Sumdiv(poj1845)

    题意:求A^B的因子的和. /* 首先将A分解 A=p1^a1*p2^a2*...*pn*an A^B=p1^a1B*p2^a2B*...*pn*anB 因子之和sum=(1+p1+p1^2+...+ ...

  7. Tyvj 1176 火焰巨魔的惆怅

    Tyvj 1176 火焰巨魔的惆怅 背景 TYVJ2月月赛第一道 巨魔家族在某天受到了其他种族的屠杀,作为一个英雄,他主动担任了断后的任务,但是,在巨魔家族整体转移过后,火焰巨魔却被困住了,他出逃的方 ...

  8. ajax分页查询信息的通用方法

    1.页面准备分页的表格与分页div 同时需要在查询条件表单中准备隐藏当前页与页大小的文本框 <div class="container-fluid"> <div ...

  9. SecureCRT在Tab下的Title显示IP

    注意:要针对每个Session进行修改才行. 参考: http://www.cnblogs.com/tyhmj/archive/2013/12/20/3483247.html

  10. JSP标准标签库(JSTL)

    JSTL:JSP Standard Tag Library:JSP标准标签库 以下内容引用自http://wiki.jikexueyuan.com/project/jsp/standard-tag-l ...