CodeForces 482B Interesting Array
来源:互联网 发布:linux倒序 ll 编辑:程序博客网 时间:2024/05/12 17:26
Description
We'll call an array of n non-negative integersa[1], a[2], ..., a[n]interesting, if it meetsm constraints. The i-th of the m constraints consists of three integersli,ri,qi (1 ≤ li ≤ ri ≤ n) meaning that value should be equal toqi.
Your task is to find any interesting array ofn elements or state that such array doesn't exist.
Expression x&y means the bitwise AND of numbersx and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal — as "and".
Input
The first line contains two integers n,m (1 ≤ n ≤ 105,1 ≤ m ≤ 105) — the number of elements in the array and the number of limits.
Each of the next m lines contains three integersli,ri,qi (1 ≤ li ≤ ri ≤ n,0 ≤ qi < 230) describing thei-th limit.
Output
If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line printn integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing theinteresting array. If there are multiple answers, print any of them.
If the interesting array doesn't exist, print "NO" (without the quotes) in the single line.
Sample Input
3 11 3 3
YES3 3 3
3 21 3 31 3 2
NO
/** 题意:给n个数和m个操作,每个操作形如: l r x, 表示a[l] & a[l+1] & ... &a[r] = x; 问:是否存在这样一个序列满足所给操作? 有:输出YES,并输出这个序列。 没有:输出NO。 分析:考虑a[i],对于所有包含它的操作,如果取与操作后为x, 则x的二进制为1的位上,a[i]也为1。 其他位都为0肯定是满足的。 那么我们可以对所有x取或,得到的就是a[i]。 线段树区间操作就不多说了。 最后,检验序列是否符合要求。 */#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<set>using namespace std;const int N = 100001;int ans[N],mak[N<<2];int ql[N],qr[N],qx[N];void pushdown(int rt){ if(!mak[rt]) return ; mak[rt<<1]|=mak[rt]; mak[rt<<1|1]|=mak[rt]; mak[rt] = 0;}void update(int L, int R, int x, int l, int r, int rt){ if(L<=l && R>=r) { mak[rt]|=x; return; } int m = l+r>>1; if(L<=m) update(L,R,x,l,m,rt<<1); if(R>m) update(L,R,x,m+1,r,rt<<1|1);}void solve(int l, int r, int rt){ if(l==r) { ans[l] = mak[rt]; return ; } int m = l+r>>1; pushdown(rt); solve(l,m,rt<<1); solve(m+1,r,rt<<1|1);}void build(int l, int r, int rt){ if(l==r) { mak[rt] = ans[l]; return ; } int m = l+r>>1; build(l,m,rt<<1); build(m+1,r,rt<<1|1); mak[rt] = mak[rt<<1]&mak[rt<<1|1];}int query(int L, int R, int l, int r, int rt){ if(L<=l && R>=r) return mak[rt]; int m = l+r>>1; int s = (1<<30)-1; if(L<=m) s&=query(L,R,l,m,rt<<1); if(R>m) s&=query(L,R,m+1,r,rt<<1|1); return s;}int main(){ int i,j,k,m,n; while(scanf("%d %d",&n,&m)==2) { memset(mak,0,sizeof(mak)); for(i=1; i<=m; i++) { scanf("%d%d%d",ql+i,qr+i,qx+i); update(ql[i],qr[i],qx[i],1,n,1); } solve(1,n,1); build(1,n,1); bool ok = true; for(i=1; i<=m; i++) { int a = query(ql[i],qr[i],1,n,1); if(a!=qx[i]) { ok = false; break; } } if(!ok) { puts("NO"); continue; }; puts("YES"); for(i=1; i<n; i++) printf("%d ",ans[i]); printf("%d\n",ans[n]); } return 0;}
- CodeForces 482 B. Interesting Array
- CodeForces 482B Interesting Array
- codeforces 482B Interesting Array
- codeforces 482B Interesting Array 线段树
- Codeforces 482B Interesting Array(线段树)
- Codeforces 482B. Interesting Array 线段树
- Interesting Array - CodeForces 482 B 线段树
- CodeForces 482B-Interesting Array(线段树)
- 482 B. Interesting Array
- 482B - Interesting Array
- Codeforces 482B Interesting Array 构造+线段树判可行
- codeforces 482B. Interesting Array【线段树区间更新】
- codeforces 482 B Interesting Array 线段树区间更新
- codeforces 482 B Interesting Array <STL map 的运用>
- CF 482 B. Interesting Array 线段树
- Codeforces Round #275 (Div. 1) B.Interesting Array
- Codeforces Round #275 Div.1 B Interesting Array --线段树
- 【CODEFORCES】 D. Interesting Array
- 纯码农的尴尬
- Android 依赖注入函数库Roboguice(一)
- ubuntu12.04将当前终端的jdk环境临时切换到jdk1.7
- linux grep命令详解
- Photoshop脚本 > 查看图层边界信息
- CodeForces 482B Interesting Array
- Sharepoint2013 webpart 使用Jquery+json数据实现的菜单。
- InorderTraversal非递归实现
- 但是对于Hibernate3.6.5会报错PersistenceException包含如下信息:
- Photoshop脚本 > 复制一份当前文档
- UVa 884 - Factorial Factors
- C#.NET各种连接字符串
- AVAudioSession
- Photoshop脚本 > 压缩并输出GIF图片