Codeforces 482B Interesting Array(线段树区间更新)
题目链接 Interesting Array
区间更新。然后对于每一个约数重新求一遍区间的&值,不符合就跳出。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define lson i << 1, L, mid
#define rson i << 1 | 1, mid + 1, R const int N = ; struct node{
int l, r, val;
} a[N]; int tree[N << ], ans[N];
int n, m;
int ret = ; void update(int i, int L, int R, int l, int r, int val){
if (L == l && R == r){ tree[i] |= val; return ;}
int mid = (L + R) >> ;
if (r <= mid) update(lson, l, r, val);
else if (l > mid) update(rson, l, r, val);
else{
update(lson, l, mid, val);
update(rson, mid + , r, val);
}
} int query(int i, int L, int R, int l, int r){
if (L == l && R == r) return tree[i];
int mid = (L + R) >> ;
if (r <= mid) return query(lson, l, r);
else if (l > mid) return query(rson, l, r);
else return query(lson, l, mid) & query(rson, mid + , r);
} void Work(int i, int L, int R){
tree[i] |= tree[i >> ];
if (L == R){ ans[++ret] = tree[i]; return ;}
int mid = (L + R) >> ;
Work(lson);
Work(rson);
} int main(){ scanf("%d%d", &n, &m); memset(tree, , sizeof tree);
rep(i, , m){
scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].val);
update(, , n, a[i].l, a[i].r, a[i].val);
} bool flag = true; rep(i, , m){
int cnt = query(, , n, a[i].l, a[i].r);
if (cnt != a[i].val){
flag = false;
break;
}
} if (flag) Work(, , n); else return * puts("NO");
puts("YES"); rep(i, , ret) printf("%d ", ans[i]); return ;
}
Codeforces 482B Interesting Array(线段树区间更新)的更多相关文章
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- CF#52 C Circular RMQ (线段树区间更新)
Description You are given circular array a0, a1, ..., an - 1. There are two types of operations with ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
随机推荐
- dp专练
dp练习. codevs 1048 石子归并 区间dp #include<cstdio> #include<algorithm> #include<cstring> ...
- idea 安装findBugs 可以做代码扫描,也可以导出扫描结果生成扫描报告
idea 安装findBugs 可以做代码扫描,也可以导出扫描结果生成扫描报告 https://my.oschina.net/viakiba/blog/1838296 https://www.cnbl ...
- 单例模式【python】
在python中,如需让一个类只能创建一个实例对象,怎么能才能做到呢? 思路:1.通过同一个类创建的不同对象,都让他们指向同一个方向. 2.让个类只能创建唯一的实例对象. 方法:用到 _ _new ...
- 【Luogu P1637】 三元上升子序列
对于每个数$a_i$,易得它对答案的贡献为 它左边比它小的数的个数$\times$它右边比它大的数的个数. 可以离散化后再处理也可以使用动态开点的线段树. 我使用了动态开点的线段树,只有需要用到这个节 ...
- python - 接口自动化测试 - TestRegister - 注册接口测试用例
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: test_register.py @ide: PyChar ...
- [状态更新]MSE三个月快速复习计划,成功考上复旦软工
最后更新,6月21日收到录取通知书啦,感谢当初不曾放弃的自己: 更新一下状态: 3.3日 分数出来了,过了复试线. 最初写这篇博客的时候,是希望自己能够每天或者至少每周更新下自己的复习状态,这样能够确 ...
- jquery判断元素是否存在在数组中
var myArray = new Array(); function checkRepeat(sel) { console.log("索引是:" + $.inArray(sel, ...
- hdu5985[概率dp] 2016青岛icpc现场赛
#include <bits/stdc++.h> using namespace std; ][]; ][]; ][]; ]; ]; int T, n; double fastpow(do ...
- HTTP协议详解之消息报头
原文地址:http://www.cnblogs.com/devinzhang/archive/2012/02/06/2340186.html HTTP消息由客户端到服务器的请求和服务器到客户端的响应组 ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...