482B - Interesting Array
来源:互联网 发布:网络推广的计划方案 编辑:程序博客网 时间:2024/05/18 02:54
题意:构造一个串,满足m个条件,每个条件表示将l到r区间内的数相与的结果等于q,求这样的串是否存在,若存在则输出任意一种情况
思路:看似构造题,实则用数据结构的思路去解会比较方便,由于要执行的是&操作,所以明显可知在l到r范围内的所有数都必须存在包含q,这里的包含指x&q=q,所以对于一个l,r,为了得到q,每个数都需要或上一个q,这部分可以用线段树成段更新去实现,最后我们需要验证我们将所有的q或上去之后的串是否仍保证满足所有的条件
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1const int maxn = 111111;int col[maxn<<2];int sum[maxn<<2];void PushUp(int rt) {sum[rt] = sum[rt<<1] & sum[rt<<1|1];}void PushDown(int rt,int m) {if (col[rt]) { col[rt<<1] |=col[rt];col[rt<<1|1] |= col[rt];sum[rt<<1] |= col[rt];sum[rt<<1|1] |= col[rt];col[rt] = 0;}}void update(int L,int R,int c,int l,int r,int rt) {if (L <= l && r <= R) {col[rt] |= c;sum[rt] |= c; return ;}PushDown(rt , r - l + 1);int m = (l + r) >> 1;if (L <= m) update(L , R , c , lson);if (R > m) update(L , R , c , rson);PushUp(rt);}int query(int L,int R,int l,int r,int rt){if(L<=l && r<=R){return sum[rt];}PushDown(rt,r-l+1);int m=(l+r)>>1;int temp;bool mark=0;if(L<=m){temp=query(L,R,lson);mark=1;}if(R>m) {if(mark)temp&=query(L,R,rson);else temp=query(L,R,rson);}PushUp(rt);return temp;}int n,m;int l[maxn],r[maxn],q[maxn];int main(){int i,j;scanf("%d%d",&n,&m);memset(col,0,sizeof(col));memset(sum,0,sizeof(sum));for(i=0;i<m;i++){scanf("%d%d%d",&l[i],&r[i],&q[i]);update(l[i],r[i],q[i],1,n,1);}bool flag=0;for(i=0;i<m;i++){if(query(l[i],r[i],1,n,1)!=q[i]){flag=1;break;}}if(flag) puts("NO");else {puts("YES");for(i=1;i<=n;i++)printf("%d ",query(i,i,1,n,1));}return 0;}
0 0
- 482 B. Interesting Array
- 482B - Interesting Array
- 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(线段树)
- CF 482 B. Interesting Array 线段树
- Codeforces 482B Interesting Array 构造+线段树判可行
- codeforces 482B. Interesting Array【线段树区间更新】
- codeforces 482 B Interesting Array 线段树区间更新
- codeforces 482 B Interesting Array <STL map 的运用>
- Codeforces Round #275 (Div. 1) B.Interesting Array
- Codeforces Round #275 Div.1 B Interesting Array --线段树
- 【CODEFORCES】 D. Interesting Array
- java接口
- Android之shape与selector实现圆角
- 第6章 Linux网络侦错
- 与路径处理相关的WIN32 API
- 【译转】网页设计=艺术+技术+营销
- 482B - Interesting Array
- 语音助手为什么需要搜索?
- 第十周项目五 输出完数
- Xcode打包ipa包
- 修复UISearchDisplayControllerd的searchResultsTableView的contentSize不正确
- 日语学习之新版初级标准日本语-11 小野さんは 歌が 好きです
- Ubuntu环境变量文件介绍
- mysql.sock丢失
- 知名互联网公司网站架构图