[题目链接]

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. Android四大核心组件之Activity

    一.活动生命周期 二.生命周期执行介绍 当该页面(Activity)被启动时 会执行onCreate().onStart().onRestart()这三个方法, 只有当onRestart() 方法执行 ...

  2. Python之面向对象新式类和经典类

    Python之面向对象新式类和经典类 新式类和经典类的继承原理: 在Python3中,就只有新式类一种了. 先看Python3中新式类: 类是有继承顺序的: Python的类是可以继承多个类的,也就是 ...

  3. SQL-Redis使用详细教程

    一.Redis基础部分: 1.redis介绍与安装比mysql快10倍以上 *****************redis适用场合**************** 1.取最新N个数据的操作 2.排行榜应 ...

  4. ICPC模板排版工具

    感谢参考:https://www.cnblogs.com/palayutm/p/6444833.html 额外安装texlive, ubuntu环境提供参考: 1.下载镜像包 https://mirr ...

  5. Light oj-1002 - Country Roads,迪杰斯特拉变形,不错不错~~

                                                                                               1002 - Co ...

  6. Chrome & CORS & Fetch API & Chrome 多开,应用分身

    Chrome & CORS & Fetch API Chrome 浏览器的跨域设置 https://www.cnblogs.com/cshi/p/5660039.html https: ...

  7. HDU 2442

    状态压缩DP , 和HDU2280极其相似 #include <cstdio> #include <cstring> #include <iostream> usi ...

  8. hdu 1698区间延迟更新

    #include<stdio.h> #define N 100100 struct node { int x,y,yanchi; }a[N*4];//注意数组范围 void build(i ...

  9. Nginx 的 server_names_hash_bucket_size 问题

    在 Nginx 0.6.35 的版本中,配置多个 server 虚拟主机,必须要在配置文档中 http { 里头加上 server_names_hash_bucket_size 64; 这么一句 ht ...

  10. linux 常见名词及命令(六)

    查看软件安装位置 : dpkg -L 软件包名字 ubuntu环境的apache相关命令: 查看是否启动:ps -aux | grep httpd  或者 netstat -an | grep :80 ...