[题解]codeforces 339d Xenia and Bit Operations
来源:互联网 发布:石家庄整站优化 编辑:程序博客网 时间:2024/06/09 18:13
Description
题目大意:
给你
Solution
线段树模拟就好了,每次单点修改,每层节点用bool变量记录下是该进行“或操作”还是“异或操作”。
代码:
#include<cstdio>#include<algorithm>using namespace std;template<typename T>inline void read(T &x){ T f=1;char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1; for(x=0;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0'; x*=f;}const int maxn=132010;struct Segment_Tree{ #define lc x<<1 #define rc x<<1|1 int L[maxn<<2],R[maxn<<2],sum[maxn<<2]; bool f[maxn<<2]; bool Build(int x,int *a,int l,int r){ L[x]=l;R[x]=r; if(l==r)return sum[x]=a[l],f[x]=true; int mid=(l+r)>>1; if(Build(lc,a,l,mid),Build(rc,a,mid+1,r)) return sum[x]=sum[lc]|sum[rc],f[x]=false; else return sum[x]=sum[lc]^sum[rc],f[x]=true; } void Change(int x,int pos,int val){ if(L[x]==R[x])return sum[x]=val,void(); int mid=(L[x]+R[x])>>1; if(pos<=mid)Change(lc,pos,val); else Change(rc,pos,val); if(!f[x])sum[x]=sum[lc]|sum[rc]; else sum[x]=sum[lc]^sum[rc]; }}tree;int n,m,a[maxn];int main(){ read(n);read(m);n=1<<n; for(int i=1;i<=n;i++)read(a[i]); tree.Build(1,a,1,n); while(m--){ int pos,x; read(pos);read(x); tree.Change(1,pos,x); printf("%d\n",tree.sum[1]); } return 0;}
阅读全文
0 0
- [题解]codeforces 339d Xenia and Bit Operations
- CodeForces 339D Xenia and Bit Operations
- CodeForces 339D Xenia and Bit Operations
- codeforces 339 D.Xenia and Bit Operations(线段树)
- codeforces 339D Xenia and Bit Operations 线段树
- CodeForces 339D Xenia and Bit Operations 线段树
- Codeforces 339D Xenia and Bit Operations 线段树
- CodeForces 339D Xenia and Bit Operations(线段树)
- CodeForces 339D Xenia and Bit Operations (线段树水题)
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
- CodeForces 339D D. Xenia and Bit Operations(线段树的单点更新)
- Codeforces 339D Xenia and Bit Operations 线段树单点修改
- CodeForces 339D Xenia and Bit Operations(线段树点修改)
- CodeForces 339D Xenia and Bit Operations 数据结构+线段树+点更新
- CF 339D - Xenia and Bit Operations(线段树)
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations - 线段树
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations(容器做法)
- 测试区块链的防篡改性
- Runtime error——Explorer.EXE
- geth配置中,genesis.json的几个问题
- iOS在view中绘制不规则图形
- tiny6410的IIC裸机驱动
- [题解]codeforces 339d Xenia and Bit Operations
- 【Linux API】Sysfs & sysfs_notify文件系统
- 图象直方图的线性变换——直方图拉伸
- 玩转h5之layaide设计fd编程
- python写算法题:leetcode: 31. Next Permutation
- win10+mysql
- 对象模型图(OMD)
- java NIO基本操作
- 常用的hash算法