CF482B Interesting Array(线段树+位运算)
来源:互联网 发布:澳煦广告传媒php 编辑:程序博客网 时间:2024/05/21 09:32
限制是区间按位与的结果必须为x,则根据按位与的性质,区间内的每一个数都至少“有”x,因此我们可以给这个区间的所有数或上x。因此我们先根据m个操作进行m个区间或操作。然后m次查询区间与是否满足要求。因此我们还要维护区间与。线段树即可。
#include <bits/stdc++.h>using namespace std;#define ll long long#define N 100010int const inf=(1<<30)-1;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,m,a[N];struct qu{ int x,y,val;}q[N];struct node{ int x,lazy;}tree[N<<2];inline void pushup(int p){ tree[p].x=tree[p<<1].x&tree[p<<1|1].x;}inline void pushdown(int p){ if(!tree[p].lazy) return;int val=tree[p].lazy;tree[p].lazy=0; tree[p<<1].lazy|=val;tree[p<<1|1].lazy|=val; tree[p<<1].x|=val;tree[p<<1|1].x|=val;}void build(int p,int l,int r){ if(l==r) return; int mid=l+r>>1; build(p<<1,l,mid);build(p<<1|1,mid+1,r);}int ask(int p,int l,int r,int x,int y){ if(x<=l&&r<=y) return tree[p].x; int mid=l+r>>1,res=inf;pushdown(p); if(x<=mid) res&=ask(p<<1,l,mid,x,y); if(y>mid) res&=ask(p<<1|1,mid+1,r,x,y); return res;}void update(int p,int l,int r,int x,int y,int val){ if(x<=l&&r<=y){tree[p].lazy|=val;tree[p].x|=val;return;} int mid=l+r>>1;pushdown(p); if(x<=mid) update(p<<1,l,mid,x,y,val); if(y>mid) update(p<<1|1,mid+1,r,x,y,val); pushup(p);}int main(){// freopen("a.in","r",stdin); n=read();m=read();build(1,1,n); for(int i=1;i<=m;++i){ q[i].x=read(),q[i].y=read(),q[i].val=read(); update(1,1,n,q[i].x,q[i].y,q[i].val); } for(int i=1;i<=m;++i) if(ask(1,1,n,q[i].x,q[i].y)!=q[i].val){puts("NO");return 0;} puts("YES");printf("%d",ask(1,1,n,1,1)); for(int i=2;i<=n;++i) printf(" %d",ask(1,1,n,i,i)); return 0;}
阅读全文
0 0
- CF482B Interesting Array(线段树+位运算)
- codeforces 482B Interesting Array 线段树
- codeforces 483d Interesting Array 线段树
- Codeforces 482B Interesting Array(线段树)
- Codeforces 482B. Interesting Array 线段树
- Interesting Array - CodeForces 482 B 线段树
- CodeForces 482B-Interesting Array(线段树)
- CF 482 B. Interesting Array 线段树
- CodeForces-483D Interesting Array(线段树)
- Codeforces 482B Interesting Array 构造+线段树判可行
- codeforces 482B. Interesting Array【线段树区间更新】
- Codeforces Round #275 Div.1 B Interesting Array --线段树
- CF 275 div2 D. Interesting Array (线段树)
- codeforces 482 B Interesting Array 线段树区间更新
- [Codeforces #275 (Div. 2) D. Interesting Array] 线段树
- Codeforces 483D Interesting Array【思维+线段树】
- CF 483D Interesting Array 模拟+线段树
- poj2777 线段树+位运算
- Privacy Policy of MagiTile
- POJ 2918 Tudoku 笔记
- Linux——Vim
- 二维码的生成和扫描
- RecyclerView_多条目---点击事件
- CF482B Interesting Array(线段树+位运算)
- 如何判断是否有网络
- makefile
- 第四周项目三
- POJ 3074 Sudoku 笔记
- active控件分析方法
- 第四周项目四
- Redis持久化方式RBD和AOF对比
- Mybatis使用pageHelper分页插件原理