[HIHO1079]离散化(线段树、染色)
题目链接:http://hihocoder.com/problemset/problem/1079
MD坑爹,线段查询的时候左闭右开。插完挨个点找一遍扔set里,注意没染色的情况。
#include <bits/stdc++.h>
using namespace std; #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const int maxn = ;
int sum[maxn<<]; void pushDOWN(int rt) {
if(sum[rt] != -) {
sum[rt<<] = sum[rt<<|] = sum[rt];
sum[rt] = -;
}
} void update(int L, int R, int c, int l, int r, int rt) {
if(L <= l && r <= R) {
sum[rt] = c;
return;
}
pushDOWN(rt);
int m = (l + r) >> ;
if(L <= m) update(L, R, c, lson);
if(R > m) update(L, R, c, rson);
} int query(int p, int l, int r, int rt) {
if(l == r) return sum[rt];
pushDOWN(rt);
int m = (l + r) >> ;
if(p <= m) return query(p, lson);
else return query(p, rson);
} int h[maxn], hcnt;
int n, m;
int lo[maxn], hi[maxn]; int id(int x) {
return lower_bound(h, h+hcnt, x) - h + ;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d%d",&n,&m)) {
hcnt = ;
memset(sum, -, sizeof(sum));
for(int i = ; i < n; i++) {
scanf("%d%d",&lo[i], &hi[i]);
h[hcnt++] = lo[i], h[hcnt++] = hi[i];
}
sort(h, h+hcnt); hcnt = unique(h, h+hcnt) - h;
m = hcnt;
for(int i = ; i < n; i++) {
update(id(lo[i]), id(hi[i])-, i, , m, );
}
set<int> s;
s.insert(-);
for(int i = ; i <= m; i++) {
s.insert(query(i, , m, ));
// printf("%d ", query(i, 1, m, 1));
}
// printf("\n");
printf("%d\n", s.size()-);
}
return ;
}
[HIHO1079]离散化(线段树、染色)的更多相关文章
- 南阳理工 题目9:posters(离散化+线段树)
posters 时间限制:1000 ms | 内存限制:65535 KB 难度:6 描述 The citizens of Bytetown, AB, could not stand that ...
- SGU 180 Inversions(离散化 + 线段树求逆序对)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...
- 【POJ】2528 Mayor's posters ——离散化+线段树
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, A ...
- hpu校赛--雪人的高度(离散化线段树)
1721: 感恩节KK专场——雪人的高度 时间限制: 1 Sec 内存限制: 128 MB 提交: 81 解决: 35 [提交][状态][讨论版] 题目描述 大雪过后,KK决定在春秋大道的某些区间 ...
- ZOJ - 1610 经典线段树染色问题
这个是一个经典线段树染色问题,不过题目给的是左右左右坐标,即[0,3]包含0-1这一段 1-2这一段 2-3这一段,和传统的染色不太一样,不过其实也不用太着急. 我们把左边的坐标+1,即可,那么[0, ...
- 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树
[BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...
- 【bzoj4636】蒟蒻的数列 离散化+线段树
原文地址:http://www.cnblogs.com/GXZlegend/p/6801379.html 题目描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个 ...
- 离散化+线段树/二分查找/尺取法 HDOJ 4325 Flowers
题目传送门 题意:给出一些花开花落的时间,问某个时间花开的有几朵 分析:这题有好几种做法,正解应该是离散化坐标后用线段树成端更新和单点询问.还有排序后二分查找询问点之前总花开数和总花凋谢数,作差是当前 ...
- Mayor's posters (离散化线段树+对lazy的理解)
题目 题意: n(n<=10000) 个人依次贴海报,给出每张海报所贴的范围 li,ri(1<=li<=ri<=10000000) .求出最后还能看见多少张海报. 思路: 由于 ...
- 干物妹小埋 (离散化 + 线段树 + DP)
链接:https://ac.nowcoder.com/acm/contest/992/B来源:牛客网 题目描述 在之前很火的一个动漫<干物妹小埋>中,大家对小埋打游戏喝可乐的印象十分的深刻 ...
随机推荐
- php课程---JavaScript与Jquery的区别(转)
jQuery能大大简化Javascript程序的编写,我最近花时间了解了一下jQuery,把我上手过程中的笔记和大家分享出来,希望对大家有所帮助.要使用jQuery,首先要在HTML代码最前面加上对j ...
- A trip through the Graphics Pipeline 2011_08_Pixel processing – “fork phase”
In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel sha ...
- EditText中输入手机号码时,自动添加空格
输入手机号码时,自动添加空格,更容易辨别 public class PhoneWatcher implements TextWatcher { private EditText _text; publ ...
- Yii源码阅读笔记(二十四)
Module类中获取子模块,注册子模块,实例化控制器,根据路由运行指定控制器方法的注释: /** * Retrieves the child module of the specified ID. * ...
- win commands
wmic process where name="explorer.exe" delete 我想你问得应该是运行命令吧!我查了,没有,你自己参考一下:Windows常用命令集 wi ...
- iOS CAShapeLayer记录
基本知识 看看官方说明: /* The shape layer draws a cubic Bezier spline in its coordinate space. * * The spline ...
- UIView添加手势
_shareImage.userInteractionEnabled=YES; UITapGestureRecognizer *imagegesture=[[UITapGestureRecognize ...
- 安装LNMP之后出现 Access denied.解决方法
权限问题, 执行 sudo chown -R www:www /home/wwwroot
- Redis常用的30个命令
转自http://www.jb51.net/article/51884.htm 1,connect 描述:实例连接到一个Redis.参数:host: string,port: int返回值:BOOL ...
- [CC]Plugin-提取ISS3D关键点
基于CloudCompare开发的提取ISS3D关键点. void qLxPluginPCL::doISS3D() { assert(m_app); if (!m_app) return; const ...