BZOJ5168: [HAOI2014]贴海报 线段树
Description
Input
Output
Sample Input
1 4
2 6
8 10
3 4
7 10
Sample Output
Solution
倒序处理...没想到这个就一直写不出来啊...
用线段树维护区间信息。如果这个海报的区间被覆盖了,那么显然就是被后面的海报覆盖过了,那么最后肯定就看不到这张海报了,这张海报就不用统计了
更新区间信息的时候&一下左右儿子就可以了
#include <bits/stdc++.h> #define ll long long
#define inf 0x3f3f3f3f
#define il inline namespace io { #define in(a) a=read()
#define out(a) write(a)
#define outn(a) out(a),putchar('\n') #define I_int int
inline I_int read() {
I_int x = , f = ; char c = getchar() ;
while( c < '' || c > '' ) { if( c == '-' ) f = - ; c = getchar() ; }
while( c >= '' && c <= '' ) { x = x * + c - '' ; c = getchar() ; }
return x * f ;
}
char F[ ] ;
inline void write( I_int x ) {
I_int tmp = x > ? x : -x ;
if( x < ) putchar( '-' ) ;
int cnt = ;
while( tmp > ) {
F[ cnt ++ ] = tmp % + '' ;
tmp /= ;
}
while( cnt > ) putchar( F[ -- cnt ] ) ;
}
#undef I_int }
using namespace io ; using namespace std ; #define N 100010
const int M = 1e7 + ;
#define lc (rt<<1)
#define rc (rt<<1|1) int n = read() , m = read() ;
int a[ N ] , b[ N ] ;
int cover[ M << ] ;
int bc = ; void upd( int L , int R , int l , int r , int rt ) {
if( cover[ rt ] ) return ;
if( L <= l && r <= R && !cover[ rt ] ) { cover[ rt ] = ; bc = ; return ; }
int mid = ( l + r ) >> ;
if( L <= mid ) upd( L , R , l , mid , lc ) ;
if( R > mid ) upd( L , R , mid + , r , rc ) ;
cover[ rt ] = cover[ lc ] & cover[ rc ] ;
} int main() {
int ans = ;
for( int i = ; i <= m ; i ++ ) a[ i ] = read() , b[ i ] = read() ;
for( int i = m ; i ; i -- ) {
bc = ;
upd( a[ i ] , b[ i ] , , n , ) ;
if( !bc ) ans ++ ;
}
outn( ans ) ;
}
BZOJ5168: [HAOI2014]贴海报 线段树的更多相关文章
- Luogu P3740 [HAOI2014] 贴海报 线段树
线段树版的海报 实际上这个与普通的线段树相差不大,只是貌似数据太水,暴力都可以过啊 本来以为要离散的,结果没打就A了 #include<iostream> #include<cstd ...
- BZOJ 5168 && Luogu P3740 [HAOI2014]贴海报 线段树~~
据说某谷数据十分水...但幸好BZOJ上也过了...话说我记得讲课时讲的是奇奇怪怪的离散化..但现在突然觉得什么都可以线段树瞎搞了...QAQ 直接就是这个区间有没有被覆盖,被覆盖直接return: ...
- BZOJ5029: 贴小广告 & BZOJ5168: [HAOI2014]贴海报
[传送门:BZOJ5029&BZOJ5168] 简要题意: 给出m段区间l[i],r[i],表示l[i]到r[i]的数全部变成i,求出最后有多少种不同的数 题解: 线段树+离散化 这是一道经典 ...
- POJ 2528 Mayor's posters 贴海报 线段树 区间更新
注意离散化!!!线段树的叶子结点代表的是一段!!! 给出下面两个简单的例子应该能体现普通离散化的缺陷: 1-10 1-4 5-10 1-10 1-4 6-10 普通离散化算出来的结果都会是2,但是第二 ...
- bzoj5029: 贴小广告&&bzoj5168: [HAOI2014]贴海报
以后做双精题请至少先跑个数据...输入都不一样... 做法就是离散化大力线段树. 记得在x+1和y-1插点 看这个数据: 1000 121 10050 8080 9950 981 56100 2002 ...
- Luogu P3740 [HAOI2014]贴海报_线段树
线段树版的海报 实际上这个与普通的线段树相差不大,只是貌似数据太水,暴力都可以过啊 本来以为要离散的,结果没打就A了 #include<iostream> #include<cstd ...
- 【线段树】【P3740】 [HAOI2014]贴海报
传送门 Description Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论.为了统一管理,城市委员会为选民准备了一个张贴海报的electoral墙. 张贴规 ...
- poj 2528(线段树+离散化) 市长的海报
http://poj.org/problem?id=2528 题目大意是市长竞选要贴海报,给出墙的长度和依次张贴的海报的长度区间(参考题目给的图),问最后你能看见的海报有几张 就是有的先贴的海报可能会 ...
- 线段树-hdu2795 Billboard(贴海报)
hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接 ...
随机推荐
- Jquery-plugins-toastr-消息提示
toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 html <link rel ...
- git 生成patch 和打入patch
转载:https://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用gi ...
- 调用sklearn包中的PLA算法[转载]
转自:https://blog.csdn.net/u010626937/article/details/72896144#commentBox 1.Python的机器学习包sklearn中也包含了感知 ...
- [LeetCode] 851. Loud and Rich_ Medium tag: DFS
In a group of N people (labelled 0, 1, 2, ..., N-1), each person has different amounts of money, and ...
- [LeetCode] 724. Find Pivot Index_Easy tag: Dynamic Programming
Given an array of integers nums, write a method that returns the "pivot" index of this arr ...
- pod 的warning一定要注意消除,要不然你的pod配置有问题无法导入
and the CHANGELOG for this version http://git.io/BaH8pQ. Downloading dependencies Using BlocksKit (2 ...
- 008-centos服务管理
- jquery ui draggable,droppable 学习总结
刚接触的时候,分不清draggable和droppable的区别,瞎弄了一会,其实很简单,draggable就是“拖”的功能,droppable就是“放”的功能. draggable()是被拖动的元素 ...
- Python 为什么sys.stdout.write 输出时后面总跟一个数字
sys.stdout 是标准输出文件.write就是往这个文件写数据. 合起来就是打印数据到标准输出 因为-在交互模式下会输出函数返回值,而write会返回输出的字符数量.在命令行里不会显示
- 应用程序无法正常启动0xc000007b怎么解决
解决方法两种: 1. 网上搜索中最常见的,缺少DirectX 9 ,去下载一个安上就OK了. 2.第二种情况比较操蛋,其实报的错误应该是:mfc100u.dll丢失 .我在两台电脑上装了相同系统后,台 ...