kuangbin_SegTree D (POJ 2528)
讲道理我之前暂时跳过染色的题是因为总觉得有什么很高端的算法来query
直到我做了F题(ZOJ 1610)才发现就是个暴力统计.....也对 也就几万个长度单位而已....
F就不po上来了 选了有点难度的D题 需要用到离散化
单纯的离散化又会碰到后染色覆盖前染色的 所以要在每两个差距大于1的位置之间插入一个位置
以上思路参考了 http://blog.csdn.net/non_cease/article/details/7383736 但是原po的有点小错 混过了POJ的数据但是确实是错的...
就是说底色可能会被不小心算进去 所以统计的时候要忽略底色
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f3f
#define mem(str,x) memset(str,(x),sizeof(str))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long LL; const int MAXN = ;
int n, hash[MAXN<<], col[MAXN<<];
int ans, li[MAXN], ri[MAXN];
bool vis[MAXN]; inline void push_down(int rt){
if(~col[rt]){
col[rt<<] = col[rt<<|] = col[rt];
col[rt] = -;
}
} void update(int L, int R, int c, int l, int r, int rt)
{
if(L <= l && R >= r){
col[rt] = c;
//printf("%d - %d : %d\n", l, r, c);
return;
} push_down(rt);
int m = (l + r) >> ;
if(L <= m) update(L, R, c, lson);
if(R > m) update(L, R, c, rson);
} void query(int l, int r, int rt)
{
if(l == r){
if(!vis[col[rt]] && ~col[rt]){
//printf("%d at %d\n", col[rt], l);
ans++;
vis[col[rt]] = true;
}
return;
} push_down(rt);
int m = (l + r) >> ;
query(lson);
query(rson);
} int binary_search(int l, int r, int c)
{
int m;
while(l <= r){
m = (l + r) >> ;
if(hash[m] == c) return m;
else if(hash[m] > c) r = m - ;
else l = m + ;
}
return -;
} int main()
{
int t;
scanf("%d", &t);
while(t--){
mem(col, -);
mem(vis, false);
scanf("%d", &n);
int nn = , mm = ;
for(int i = ; i <= n; i++){
scanf("%d%d", &li[i], &ri[i]);
hash[++nn] = li[i];
hash[++nn] = ri[i];
}
sort(hash+, hash++nn);
//去除重复数据
for(int i = ; i <= nn; i++){
if(hash[i] != hash[i-]) hash[++mm] = hash[i];
}
//在相距超过1的点之间插入一个点防止覆盖
for(int i = mm; i > ; i--){
if(hash[i] - hash[i-] > ) hash[++mm] = hash[i] - ;
}
sort(hash+, hash++mm);
//离散化构造线段树
for(int i = ; i <= n; i++){
int l = binary_search(, mm, li[i]);
int r = binary_search(, mm, ri[i]);
update(l, r, i, , mm, );
//printf("%d - %d : %d\n", l, r, i);
}
ans = ;
query(, mm, );
printf("%d\n", ans);
}
return ;
}
kuangbin_SegTree D (POJ 2528)的更多相关文章
- POJ 2528 Mayor's posters
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- poj 2528 (线段树+离散化)
poj 2528 For each input data set print the number of visible posters after all the posters are place ...
- POJ - 2528 Mayor's posters(dfs+分治)
POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 2528 线段树区间修改+离散化
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...
随机推荐
- VM virtuaBox异常关机启动不了的解决方案
事件回放 我的物理机是win7,上面装了一个VM virtualBox,用来装Centos,有天物理机非正常关闭,导致VM virtuaBox异常关机启动不了,如下: 确实找不到这个vm_liang. ...
- VMware-workstation-full-11.0.0-2305329&VMware-player-7.0.0-2305329
VMware-workstation-full-11.0.0-2305329.exe Name: VMware-workstation-full-11.0.0-2305329.exe 发行日期: 20 ...
- iOS---初识Swift(一)
一.Swift简介 ○ 2010年的夏天, 苹果公司的开发人员Chris Latten接到了一个特别的任务, 为OS X 和iOS平台开发下一代编程语言, 也就是Swift. ○ 苹果公司于2014年 ...
- 开源一个完整的iOSApp《丁丁美图》供初学者学习
学习iOS开发的时候,得益于开源社区的大量开源项目,去年开始购买了个人开发者账号,写了这个练手项目<丁丁美图>,并上传到了App Store(Ipad版本被驳回也懒得处理).现在将代码开源 ...
- Spark MLlib 之 Basic Statistics
Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...
- ZBJ的linux
PHP服务器 PHP服务器的IP可以ping出来 目录结构:a.代码目录统一为: /data/www/html/zbjv6b.Nginx 配置文件目:/etc/nginx/sites-enabledc ...
- compare
icompareble 默认的比较器 list.sort() compareto icompare Keyvaluepair<k,p>Where k:new()
- 学习SVG系列(4):SVG滤镜效果
注意:Internet Explorer和Safari不支持SVG滤镜 <defs>.<filter> 所有互联网的SVG滤镜定义在<defs>元素中,<fi ...
- nginx 在windows平台上对asp.net做反向代理
代理服务器 当客户机向站点提出请求时,请求将转到代理服务器.然后,代理服务器通过防火墙中的特定通路,将客户机的请求发送到内容服务器.内容服务器再通过该通道将结果回传给代理服务器.代理服务器将检索到的信 ...
- 开源一个silverlight上的文本编辑器:SlEditor
控件设置三个状态:编辑.设计.查看. 控件的内容可以打包保存为zip格式,内容可以包含图片等元素(解决了silverlight RichTextBox控件xaml属性无法获取InlineUIConta ...