CF 275 div2 D. Interesting Array (线段树)
来源:互联网 发布:2008r2数据库安装图解 编辑:程序博客网 时间:2024/06/06 01:02
题目:http://codeforces.com/contest/483/problem/D
题意:输入n和m,代表有n个数字和m条规定。接下来有m条规定,每条规定有3个数字x[i],y[i],q[i],说明区间[x[i],y[i]]的&运算的结果为q[i]。如果所有的规定都合法,输出这n个数字。
分析:建30个线段树,每个线段树维护1~n个数字的二进制数中的其中一位。(也可也压缩到一个线段树)
代码:
#include <iostream>#include <sstream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <map>#include <set>//#include <unordered_map>//#include <unordered_set>#include <utility>#include <stack>#include <deque>#include <queue>#include <list>#include <bitset>using namespace std;typedef long long LL;typedef unsigned long long ULL;#define MAXN 100005#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define rep(i,x) for(int i=0;i<x;i++)int x[MAXN],y[MAXN],q[MAXN],ans[MAXN];struct segtree{ private : bool tree[MAXN<<2]; public : void Clear(int l,int r,int rt) { tree[rt]=false; if(l==r) return ; int m=(l+r)>>1; Clear(lson); Clear(rson); } void Pushdown(int rt) { if(tree[rt]) tree[rt<<1|1]=tree[rt<<1]=true; } void Pushup(int rt) { if(tree[rt<<1|1] && tree[rt<<1]) tree[rt]=true; } void Updata(int L,int R,int l,int r,int rt) { if(L<=l && r<=R) { tree[rt]=true; return ; } Pushdown(rt); int m=(l+r)>>1; if(L<=m) Updata(L,R,lson); if(R>m) Updata(L,R,rson); Pushup(rt); } void Query(int L,int R,bool &ok,int l,int r,int rt) { if(ok || tree[rt]) return ; if(L<=l && r<=R) { if(!tree[rt]) ok=true; return ; } Pushdown(rt); int m=(l+r)>>1; if(L<=m) Query(L,R,ok,lson); if(R>m) Query(L,R,ok,rson); } void solve(int w,int l,int r,int rt) { if(l==r) { if(tree[rt]) ans[l]+=(1<<w); return ; } Pushdown(rt); int m=(l+r)>>1; solve(w,lson); solve(w,rson); } void debug(int l,int r,int rt) { printf("[%d %d]:%d\n",l,r,(tree[rt]?1:0)); if(l==r) return ; int m=(l+r)>>1; debug(lson); debug(rson); }}T[32];int main(){ int n,m,i,j,k,w,value; bool ok,f; scanf("%d%d",&n,&m); for(i=0;i<32;i++) T[i].Clear(1,n,1); for(i=1;i<=m;i++) { scanf("%d%d%d",&x[i],&y[i],&q[i]); for(j=0;j<31;j++) if(q[i]&(1<<j)) T[j].Updata(x[i],y[i],1,n,1); } for(i=1;i<=m;i++) { for(j=0;j<31;j++) { if(!(q[i]&(1<<j))) { ok=false; T[j].Query(x[i],y[i],ok,1,n,1); if(!ok) { printf("NO\n"); return 0; } } } } printf("YES\n"); for(i=0;i<31;i++) T[i].solve(i,1,n,1); for(i=1;i<=n;i++) printf("%d ",ans[i]);// for(i=0;i<30;i++)// {// printf("tree%d:\n",i);// T[i].debug(1,n,1);// } return 0;}
0 0
- CF 275 div2 D. Interesting Array (线段树)
- CF 483D Interesting Array 模拟+线段树
- CF 482 B. Interesting Array 线段树
- [Codeforces #275 (Div. 2) D. Interesting Array] 线段树
- codeforces 483d Interesting Array 线段树
- CodeForces-483D Interesting Array(线段树)
- CF 483D - Interesting Array(TODO)
- Codeforces 483D Interesting Array【思维+线段树】
- CF #278 div2 D Strip 线段树+优先队列
- CF(#294 div2):D. A and B and Interesting Substrings
- CF#365-D. Mishka and Interesting sum-树状数组/线段树离线处理区间查询
- Codeforces Round #275 Div.1 B Interesting Array --线段树
- codeforces 482B Interesting Array 线段树
- Codeforces 482B Interesting Array(线段树)
- Codeforces 482B. Interesting Array 线段树
- Interesting Array - CodeForces 482 B 线段树
- CodeForces 482B-Interesting Array(线段树)
- CF482B Interesting Array(线段树+位运算)
- 计算机使用技巧
- Nginx在只有一个域名的情况下开启另外一个网站
- 洪泽在逃犯罪人员信息记录查询
- 【工作笔记0000】VS2012关闭解决方案或是切换最近方案导致停止工作
- MongoDB的一些简单CRUD操作
- CF 275 div2 D. Interesting Array (线段树)
- Binary_Indexed_Tree(树状数组)
- 求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000(求阶乘)
- 党援之众,无竞大义。群迷之中,无辩正论。
- CodeForces - 49E Common ancestor(dp)
- ubuntu12.04的NFS配置
- MVC和MVVM的区别和联系
- failed: ERROE OCINlsEnvironmentVariableGet(OCI_NLS_CHARSET_ID) Check NLS settings etc. at
- 深入浅出讲解:php的socket通信