题意: 构造一个序列,满足m个形如:[l,r,c] 的条件。 [l,r,c]表示[l,r]中的元素按位与(&)的和为c。

解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的按位与和至少为多少。

更新时,如果val的pos位为1,那么整个区间的按位与和pos位也应该为1,否则与出来就不对了。(这是本题解题的核心)

那么此时更新 sum[rt] |= val 即可。然后再check一遍看是否满足所有条件即可。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100007 int sum[*N],mark[*N]; void pushup(int rt)
{
sum[rt] = sum[*rt]&sum[*rt+];
} void pushdown(int l,int r,int rt)
{
if(mark[rt])
{
mark[*rt] |= mark[rt];
mark[*rt+] |= mark[rt];
sum[*rt] |= mark[rt];
sum[*rt+] |= mark[rt];
mark[rt] = ;
}
} void build(int l,int r,int rt)
{
mark[rt] = sum[rt] = ;
if(l == r)
return;
int mid = (l+r)/;
build(l,mid,*rt);
build(mid+,r,*rt+);
} void update(int l,int r,int aa,int bb,int val,int rt)
{
if(aa <= l && bb >= r)
{
sum[rt] |= val;
mark[rt] |= val;
return;
}
pushdown(l,r,rt);
int mid = (l+r)/;
if(aa <= mid) update(l,mid,aa,bb,val,*rt);
if(bb > mid) update(mid+,r,aa,bb,val,*rt+);
pushup(rt);
} int query(int l,int r,int aa,int bb,int rt)
{
if(aa <= l && bb >= r)
return sum[rt];
pushdown(l,r,rt);
int mid = (l+r)/;
if(bb <= mid) return query(l,mid,aa,bb,*rt);
else if(aa > mid) return query(mid+,r,aa,bb,*rt+);
else return (query(l,mid,aa,bb,*rt)&query(mid+,r,aa,bb,*rt+));
} void print(int l,int r,int rt)
{
if(l == r)
{
printf("%d ",sum[rt]);
return;
}
pushdown(l,r,rt);
int mid = (l+r)/;
print(l,mid,*rt);
print(mid+,r,*rt+);
} struct Q
{
int l,r,val;
}q[N]; int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(,n,);
for(i=;i<=m;i++)
{
scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].val);
update(,n,q[i].l,q[i].r,q[i].val,);
}
for(i=;i<=m;i++)
{
if(query(,n,q[i].l,q[i].r,) != q[i].val)
break;
}
if(i == m+)
puts("YES"),print(,n,),puts("");
else
puts("NO");
}
return ;
}

Codeforces Round #275 Div.1 B Interesting Array --线段树的更多相关文章

  1. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  2. Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq

    B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  3. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  4. Codeforces Round #546 (Div. 2) E 推公式 + 线段树

    https://codeforces.com/contest/1136/problem/E 题意 给你一个有n个数字的a数组,一个有n-1个数字的k数组,两种操作: 1.将a[i]+x,假如a[i]+ ...

  5. Codeforces Round #271 (Div. 2) F. Ant colony 线段树

    F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  7. Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  8. Codeforces Round #426 (Div. 2) D. The Bakery 线段树优化DP

    D. The Bakery   Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought req ...

  9. Codeforces Round #316 (Div. 2) C. Replacement(线段树)

    C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Mysql denied for user 'odbc@localhost' || denied for user 'root@localhost'

    1. Question Description: 1.1  mysql  version:  mysql-5.7.11-win64.zip 1.2  if you connect to the mys ...

  2. 中国各城市PM2.5数据间的相关分析

    code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...

  3. Jquery easyui Tree的简单使用

    Jquery easyui Tree的简单使用 Jquery easyui 是jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻 ...

  4. SharePoint 如何找到List的Template ID

    在我们添加Ribbon操作,或者对特定模板进行操作的时候,经常需要ListTemplate的数值,我们经常需要搜索各种网页,来查找匹配的ListTemplate值,其实,有个比较简便的方法. 像定义R ...

  5. C语言接口与实现实例

    一个模块有两部分组成:接口和实现.接口指明模块要做什么,它声明了使用该模块的代码可用的标识符.类型和例程,实现指明模块是如何完成其接口声明的目标的,一个给定的模块通常只有一个接口,但是可能会有许多种实 ...

  6. JSONKit解析json数据

    先将第三方文件拖进工程 JSONKit.h和JSONKit.m 然后设置在ARC工程中添加MRC文件,如下图所示 #import "ViewController.h" #impor ...

  7. Swift开发第四篇——柯里化

    本篇分为两部分: 一.柯里化的基本使用 二.柯里化的使用场景 一.柯里化的基本使用 柯里化(Currying):也就是把接受多个参数的方法变换成接受第一个参数的方法,并且返回接受余下的参数并且返回结果 ...

  8. CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)

    这篇文章主要介绍了CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)的方法,需要的朋友可以参考下 文章写的不错,很详细:IDO转载自网络: 准备篇: 1.配置防火墙,开启 ...

  9. 给定a、b两个文件,各存放50亿个url,每个url各占用64字节,内存限制是4G,如何找出a、b文件共同的url?

    给定a.b两个文件,各存放50亿个url,每个url各占用64字节,内存限制是4G,如何找出a.b文件共同的url? 可以估计每个文件的大小为5G*64=300G,远大于4G.所以不可能将其完全加载到 ...

  10. apache 开启zgip 压缩模式

    一.Apache开启gzip压缩模式在目录apache\conf\httpd.conf 配置 httpd.conf 文件: #去掉LoadModule deflate_module modules/m ...