题目大意:构造一个序列$S$,有$m$条限制,每条为$l\;r\;q$,表示$\&_{i=l}^r S_i=q$

题解:每条限制就把$[l,r]$内的数或上$q$,最后判断就行了

卡点:我又写了一课$O(n^2\log_2n)$的线段树。。。

C++ Code:

#include <cstdio>
#include <cstdlib>
#define maxn 100010
const int inf = (1 << 30) - 1;
namespace SgT {
int n;
int L, R, q;
int V[maxn << 2], tg[maxn << 2];
inline void pushdown(int rt) {
int &x = tg[rt];
V[rt << 1] |= x;
V[rt << 1 | 1] |= x;
tg[rt << 1] |= x;
tg[rt << 1 | 1] |= x;
x = 0;
}
void modify(int rt, int l, int r) {
if (L <= l && R >= r) {
V[rt] |= q;
tg[rt] |= q;
return ;
}
if (tg[rt]) pushdown(rt);
int mid = l + r >> 1;
if (L <= mid) modify(rt << 1, l, mid);
if (R > mid) modify(rt << 1 | 1, mid + 1, r);
V[rt] = V[rt << 1] & V[rt << 1 | 1];
}
inline void add(int ll, int rr, int qq) {
L = ll, R = rr, q = qq;
modify(1, 1, n);
}
int query(int rt, int l, int r) {
if (L <= l && R >= r) return V[rt];
if (tg[rt]) pushdown(rt);
int mid = l + r >> 1, ans = inf;
if (L <= mid) ans = query(rt << 1, l, mid);
if (R > mid) ans &= query(rt << 1 | 1, mid + 1, r);
return ans;
}
inline int ask(int ll, int rr) {
L = ll, R = rr;
return query(1, 1, n);
}
}
using SgT::add;
using SgT::ask;
int n, m;
int l[maxn], r[maxn], q[maxn];
int main() {
scanf("%d%d", &n, &m); SgT::n = n;
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", l + i, r + i, q + i);
add(l[i], r[i], q[i]);
}
for (int i = 1; i <= m; i++) {
if (ask(l[i], r[i]) != q[i]) {
puts("NO");
exit(0);
}
}
puts("YES");
for (int i = 1; i < n; i++) printf("%d ", ask(i, i));
printf("%d\n", ask(n, n));
return 0;
}

  

[CF482B]Interesting Array的更多相关文章

  1. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  2. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  3. Codeforces 482B Interesting Array(线段树区间更新)

    题目链接 Interesting Array 区间更新.然后对于每一个约数重新求一遍区间的&值,不符合就跳出. #include <bits/stdc++.h> using nam ...

  4. Codeforces E. Interesting Array(线段树)

    题目描述: D. Interesting Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard ...

  5. B. Interesting Array(线段树)

    B. Interesting Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #275 Div.1 B Interesting Array --线段树

    题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...

  7. Codeforces 482B Interesting Array

    题意:构造一个长度为n的序列,使其满足m个形式如下如下约束:a[l]&a[l+1]&a[l+2]&....&a[r]=q 从Dalao的博客上看到这题,决定去水水.做法 ...

  8. javascript跳跃式前进(3) - 跳入JSON

    前言 JSON崛起不是意外,是顺应时代;相当简洁小巧的书写模式及阅读方式; 基础 看这篇文章: JSON知识点汇总_W3SCHOOL 初步进阶 早期的解析仅仅实用eval() ,可是这货太easy给注 ...

  9. Codeforces 483 - A/B/C/D/E - (Done)

    题目链接:http://codeforces.com/contest/483 A - Counterexample - [简单构造题] Your friend has recently learned ...

随机推荐

  1. Python 初始—(项目 目录结构)

    在os 包下,给出 import os ,os.path.abspath(__file__)获取当前文件的相对路径,os.path.dirname 获取当前文件所在的文件夹目录 print(os.pa ...

  2. pageScope、requestScope、sessionScope、applicationScope的区别

    https://www.cnblogs.com/qianbaidu/p/6006459.html 1.区别: 1.page指当前页面有效.在一个jsp页面里有效 2.request 指在一次请求的全过 ...

  3. Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别

    int updateByPrimaryKeySelective(TbItem record); int updateByPrimaryKey(TbItem record); 上面的是逆转工程生成的Ma ...

  4. TouTiao开源项目 分析笔记4==>一个简单APP 整体常用框架

    1.效果预览 1.1.如下图所以,到目前为止所有的功能. 2.从InitApp开始->SplashActivity->MainActivity 2.1.InitApp源代码.这是整个项目的 ...

  5. 路由vue-router基础

    目录 1. 基本例子 2. 动态路由匹配 3. 嵌套路由 4. 编程式导航 5. 命名路由 6. 命名视图 7. 重定向和别名 8. 向路由组件传递props 9. HTML5 History模式 官 ...

  6. BitLocker:如何启用网络解锁

    TechNet 库Windows ServerWindows Server 2012 R2 和 Windows Server 2012服务器角色和技术安全和保护BitLockerBitLocker 中 ...

  7. Google Chrome 自定义协议(PROTOCOL)问题的处理

    最近在使用谷歌浏览器的时候遇到了自定义协议(PROTOCOL)的问题,比较折腾,特此记录,希望我浪费生命换来的结果能够帮助读到此文的朋友少浪费一点宝贵的时间! 由于某些原因,电脑里一直没有安装阿里旺旺 ...

  8. b树的实现

    花了蛮长时间实现的b树插入操作.有时间再实现其他操作. #include <stdio.h> #include <stdlib.h> #define M 5 enum KeyS ...

  9. IIS相关服务和无法启动服务W3SVC错误提示

    首先,打开“服务”查看下面的服务是否启动.(下面的两个服务就是跟IIS相关的服务,计算机(右键)->管理->服务和应用程序->服务) Windows Process Activati ...

  10. shell脚本简单切割字符串

    我们有这样一个字符串: info='abcd;efgh' 现在想获取abcd和efgh,我们可以简单地用cut工具来获取: fstr=`` sstr=`` 这里主要是用了cut工具的-d和-f参数: ...