B. Interesting Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers liriqi (1 ≤ li ≤ ri ≤ n) meaning that value  should be equal to qi.

Your task is to find any interesting array of n elements or state that such array doesn't exist.

Expression x&y means the bitwise AND of numbers x 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 nm (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 integers liriqi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit.

Output

If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n](0 ≤ a[i] < 230) decribing the interesting 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.

Examples
input
3 1
1 3 3
output
YES
3 3 3
input
3 2
1 3 3
1 3 2
output
NO

算法:线段树

题解:直接用线段树版子,更新用按位或来修改,用按位与来向上更新,要快点可以打个lazy数组。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector> using namespace std; #define INF 0x3f3f3f3f
typedef long long ll; const int maxn = 1e5+; struct node {
int l, r, s;
}tree[maxn << ]; struct queue {
int l, r, w;
}Q[maxn]; int n, m;
int lazy[maxn << ]; void build(int root, int l, int r) {
tree[root].l = l;
tree[root].r = r;
tree[root].s = ;
if(l == r) {
return;
}
int mid = (l + r) >> ;
build(root << , l, mid);
build(root << | , mid + , r);
} void pushup(int root) {
tree[root].s = tree[root << ].s & tree[root << | ].s;
} void pushdown(int root) {
if(lazy[root]) {
tree[root << ].s |= lazy[root];
tree[root << | ].s |= lazy[root];
lazy[root << ] |= lazy[root];
lazy[root << | ] |= lazy[root];
lazy[root] = ;
}
} void update(int root, int x, int y, int val) {
int l = tree[root].l;
int r = tree[root].r;
if(x <= l && r <= y) {
tree[root].s |= val;
lazy[root] |= val;
return;
}
pushdown(root);
int mid = (l + r) >> ;
if(x <= mid) {
update(root << , x, y, val);
}
if(y > mid) {
update(root << | , x, y, val);
}
pushup(root);
} int queue(int root, int x, int y) {
int l = tree[root].l;
int r = tree[root].r;
if(x <= l && r <= y) {
return tree[root].s;
}
pushdown(root);
int mid = (l + r) >> ;
int ans = ( << ) - ;
if(x <= mid) {
ans &= queue(root << , x, y);
}
if(y > mid) {
ans &= queue(root << | , x, y);
}
pushdown(root);
return ans;
} int main() {
scanf("%d %d", &n, &m);
build(, , n);
for(int i = ; i <= m; i++) {
scanf("%d %d %d", &Q[i].l, &Q[i].r, &Q[i].w);
update(, Q[i].l, Q[i].r, Q[i].w);
}
for(int i = ; i <= m; i++) {
if(queue(, Q[i].l, Q[i].r) != Q[i].w) { //如果其中有一个不满足条件的话,就输出NO
printf("NO\n");
return ;
}
}
printf("YES\n");
for(int i = ; i <= n; i++) {
printf("%d%c", queue(, i, i), " \n"[i == n]);
}
return ;
}

B. Interesting Array(线段树)的更多相关文章

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

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

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

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

  3. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

  4. 【Codeforces718C】Sasha and Array 线段树 + 矩阵乘法

    C. Sasha and Array time limit per test:5 seconds memory limit per test:256 megabytes input:standard ...

  5. codeforces 719E E. Sasha and Array(线段树)

    题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input sta ...

  6. Codeforces 1114F Please, another Queries on Array? 线段树

    Please, another Queries on Array? 利用欧拉函数的计算方法, 用线段树搞一搞就好啦. #include<bits/stdc++.h> #define LL ...

  7. 2019ccpc网络赛hdu6703 array(线段树)

    array 题目传送门 解题思路 操作1是把第pos个位置上的数加上\(10^7\),操作2是找到区间[1,r]中没有且大于k的最小的数.注意到k的范围是小于等于n的,且n的范围是\(10^5\),远 ...

  8. 暑假集训单切赛第一场 CF 266E More Queries to Array(线段树+二项式展开式)

    比赛时,第二题就是做的这个,当时果断没仔细考虑,直接用线段树暴力求.结果易想而知,超时了. 比赛后搜了搜题解,恍然大悟. 思路:显然用线段树,但是由于每次查询都会有变,所以不可能存储题目中的式子.   ...

  9. Codeforces295A - Greg and Array(线段树的成段更新)

    题目大意 给定一个序列a[1],a[2]--a[n] 接下来给出m种操作,每种操作是以下形式的: l r d 表示把区间[l,r]内的每一个数都加上一个值d 之后有k个操作,每个操作是以下形式的: x ...

  10. [Codeforces266E]More Queries to Array...——线段树

    题目链接: Codeforces266E 题目大意:给出一个序列$a$,要求完成$Q$次操作,操作分为两种:1.$l,r,x$,将$[l,r]$的数都变为$x$.2.$l,r,k$,求$\sum\li ...

随机推荐

  1. django 支持跨域请求配置

    参考:https://www.jianshu.com/p/63fb55bee142 核心注意点:

  2. Nginx支持WebSocket服务

    server{ listen ; access_log logs/.jieyun.top.log main; server_name .jieyun.top; #绑定域名 index index.ph ...

  3. 如何将编译后的文件打包成jar文件

    如果需要修改像spring和dubbo中的jar包源码,修改后怎么打包呢? 如下: 1.win+r进入命令行: 2.找到需要打包的class文件: 3.jar -cvf [jar包的名字] [需要打包 ...

  4. elementui按需加载

    定义一个ele.js文件 官网:https://element.eleme.io/#/zh-CN/component/quickstart // 方法1 import 'element-ui/lib/ ...

  5. TensorFlow教程使用RNN生成唐诗

    本教程转载至:TensorFlow练习7: 基于RNN生成古诗词 使用的数据集是全唐诗,首先提供一下数据集的下载链接:https://pan.baidu.com/s/13pNWfffr5HSN79WN ...

  6. go语言入门(3)运算符及流程控制

    1,运算符 算数运算符:+   -   *   /   %   ++   -- 关系运算符:==    !=    <    >    <=    >== 逻辑运算符:按位与 ...

  7. vue+axios请求头封装

    import { mapMutations } from 'vuex' import axios from 'axios' import { Toast } from 'mint-ui'; impor ...

  8. 第五篇.python进阶

    目录 第五篇.python进阶 1. 异常处理 2. 数字类型内置方法 2.定义: 3.常用操作+内置方法: 4.存一个值or多个值: 5.有序or无序: 6.可变和不可变 1.用途: 2.定义: 3 ...

  9. Springboot 测试类没有找到bean注入

    其他乱七八糟配置就不扯了,先上项目结构图 配置好参数后我再src/test/java类测试访问数据库时发现bean没有正确的注入.值得注意的是,这个项目的启动类是叫App.java 所以我们必须在这个 ...

  10. 从一道Hard学习滑动窗口

    滑动窗口 滑动窗口(sliding windows algorithm)这种方法,专门用于解决区间解的问题.它在运算的时候,将解集放在窗口中,结束的时候比对是否符合预期.在运算的过程中,会对窗口的左右 ...