[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来源:牛客网 题目描述 在之前很火的一个动漫<干物妹小埋>中,大家对小埋打游戏喝可乐的印象十分的深刻 ...
随机推荐
- 利用session完成用户登陆
package cn.itcast.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.L ...
- ThinkPHP 3.2.3 简单后台模块开发(一)常用配置
一.项目分组 下载解压 ThinkPHP 3.2.3,在默认的应用 Application(./Application) 中,包含一个默认的模块 Home(./Application/Home). 需 ...
- LeetCode Minimum Height Trees
原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree cha ...
- js 中escape,encodeURI,encodeURIComponent的区别
escape:方法不能能够用来对统一资源(URI)进行编码,对其编码应使用encodeURI和encodeURIComponent encodeURI:encodeURI ()方法返回一个编码的 UR ...
- MyBatis操作指南-配置结果映射一对一,一对多,多对多(基于注解)
- 【Apache】apache简单配置URL重写规则
[概述]URL重写就是首先获得一个进入的URL请求然后把它重新写成网站可以处理的另一个URL的过程.举个例子来说,如果通过浏览器进来的URL是index.php?type=news&& ...
- ios - 纯代码创建collectionView
开始考虑好一点点时间,因为一般的都是用xib,或者storyboard来写的.这次用纯代码...废话较多请看 首先把storyboard干掉,工程里面的main干掉 由于干掉了storyboard则启 ...
- [Android Tips] 1. Getting StatusBar Height
public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier(&quo ...
- Scala 环境搭建
下载安装包 1,)下载java jdk,推荐jdk1.8; 2,)下载scala安装包:http://www.scala-lang.org/; 3,)下载IDE:ide可以选择两种: 3.1,)Sca ...
- Java -- 在Eclipse上使用Spring
在.NET上用的VS.NET+Spring.net+Nhibernate,到了Java平台上,自然对应着Eclipse+Spring+Hibernate.上一篇文章介绍了如何在Eclipse上使用Hi ...