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,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
随机推荐
- python集成开发环境PyCharm
环境安装视频介绍:http://pan.baidu.com/s/1gfz6wiZ ppmb 外加几个截图: activate:
- jvm探秘之三:GC初步
GC即垃圾收集器,虚拟机的必要组成部分. 不过这里说当然是,hotspot虚拟机(jvm的主要版本)的GC机制,前面说过了jvm的组成部分,那么想当然GC只需要负责方法区和堆就好了,虚拟机栈.本地方法 ...
- UNIX 系统中 wc 程序的主要部分
以下代码为 UNIX 系统中 wc 程序的骨干部分 #include <stdio.h> #define IN 1 #define OUT 0 int main(int argc, cha ...
- ADO之密码验证--3次错误就锁定『改进』
这里使用了SqlHelper,简化程序 自己写一个SqlHelper,把数据库的连接等都写到里面去. 首先把连接字符串添加到配置文件里去,右键解决方案-->添加新建项-->选择应用程序配置 ...
- windows下使用grunt
grunt官网:http://www.gruntjs.org/ 一.安装grunt 先安装node,在http://www.nodejs.org/可以下载安装包直接安装.在命令行下运行: npm in ...
- PostgreSQL查看索引的使用情况
查看某个表的索引使用情况 select relname, indexrelname, idx_scan, idx_tup_read, idx_tup_fetch from pg_stat_user_i ...
- git和github基础入门
一.git: 1.安装配置git: 1.1从官网或者该网址处下载:https://pan.baidu.com/s/1kU5OCOB#list/path=%2Fpub%2Fgit 1.2安装,一路nex ...
- idea中将项目与github关联
© 版权声明:本文为博主原创文章,转载请注明出处 1.在github中创建一个账号:https://github.com/join?source=header-home 2.下载并安装git:http ...
- @inerface的11条规范写法
总结一些interface声明时的规范,相关宏的介绍,定义方法时有用的修饰符,编写注释的规范,最终写出一个合格的头文件. 1.读写权限 1.1实例变量的@public,@protected,@priv ...
- Google Code Jam 2008 Round 1A C Numbers(矩阵快速幂+化简方程,好题)
Problem C. Numbers This contest is open for practice. You can try every problem as many times as you ...