题目链接: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]离散化(线段树、染色)的更多相关文章

  1. 南阳理工 题目9:posters(离散化+线段树)

    posters 时间限制:1000 ms  |  内存限制:65535 KB 难度:6   描述 The citizens of Bytetown, AB, could not stand that ...

  2. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  3. 【POJ】2528 Mayor's posters ——离散化+线段树

    Mayor's posters Time Limit: 1000MS    Memory Limit: 65536K   Description The citizens of Bytetown, A ...

  4. hpu校赛--雪人的高度(离散化线段树)

    1721: 感恩节KK专场——雪人的高度 时间限制: 1 Sec  内存限制: 128 MB 提交: 81  解决: 35 [提交][状态][讨论版] 题目描述 大雪过后,KK决定在春秋大道的某些区间 ...

  5. ZOJ - 1610 经典线段树染色问题

    这个是一个经典线段树染色问题,不过题目给的是左右左右坐标,即[0,3]包含0-1这一段 1-2这一段 2-3这一段,和传统的染色不太一样,不过其实也不用太着急. 我们把左边的坐标+1,即可,那么[0, ...

  6. 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树

    [BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...

  7. 【bzoj4636】蒟蒻的数列 离散化+线段树

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801379.html 题目描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个 ...

  8. 离散化+线段树/二分查找/尺取法 HDOJ 4325 Flowers

    题目传送门 题意:给出一些花开花落的时间,问某个时间花开的有几朵 分析:这题有好几种做法,正解应该是离散化坐标后用线段树成端更新和单点询问.还有排序后二分查找询问点之前总花开数和总花凋谢数,作差是当前 ...

  9. Mayor's posters (离散化线段树+对lazy的理解)

    题目 题意: n(n<=10000) 个人依次贴海报,给出每张海报所贴的范围 li,ri(1<=li<=ri<=10000000) .求出最后还能看见多少张海报. 思路: 由于 ...

  10. 干物妹小埋 (离散化 + 线段树 + DP)

    链接:https://ac.nowcoder.com/acm/contest/992/B来源:牛客网 题目描述 在之前很火的一个动漫<干物妹小埋>中,大家对小埋打游戏喝可乐的印象十分的深刻 ...

随机推荐

  1. 【iCore3 双核心板_FPGA】例程八:触发器实验——触发器的使用

    实验指导书及代码包下载: http://pan.baidu.com/s/1bswW3c iCore3 购买链接: https://item.taobao.com/item.htm?id=5242294 ...

  2. INSTRUCTION EXECUTION CHARACTERISTICS

    Characteristics of Some CISCs, RISCs, and Superscalar Processors One of the most visible forms of ev ...

  3. C++ Primer Pluse_8_课后题

    #include <iostream> #include <string> #include<cstring> using namespace std; void ...

  4. linq小笔记;

    1.比较LINQ to Entities的AsQueryable和AsEnumerable方法 C#程序: 复制内容到剪贴板程序代码 using (testContext context = new ...

  5. PRAGMA AUTONOMOUS_TRANSACTION

    转自 http://blog.csdn.net/pan_tian/article/details/7675800 这段时间遇到一个问题,程序里明明插入了一条记录,但在后边的一段Procedure中却查 ...

  6. JSP和Server的相互转化

    [设计想法] [前置条件] 1. eclipse的web环境已经搭建OK 2. eclipse已经存在web项目"firstweb" [操作步骤] 1. "firstwe ...

  7. 忘记Linux root用户的密码怎么办?

    以前忘记windows密码的时候,要么用工具清除,要么重装系统.假如你忘记了linux系统的root密码,怎么办呢?是像windows一样用工具破解还是重装系统呢?哈哈,都不用.这方法很简单,现在做一 ...

  8. pod install出现[!] /bin/bash -c错误,Installing Realm报错

    pod install出现错误,具体错误信息如下: Installing Realm () [!] /bin/bash -c set -e sh build.sh cocoapods-setup co ...

  9. sharding-jdbc-how2work 当当的sharding-jdbc剖析(查询)

    1. 以JDBC作为出发点 1.1 重新实现了JDBC的几个接口 实现javax.sql.DataSource接口  ShardingDataSource实现java.sql.Connection接口 ...

  10. ios -- 教你如何轻松学习Swift语法(二)

    前言:swift语法基础篇(二)来了,想学习swift的朋友可以拿去参考哦,有兴趣可以相互探讨,共同学习哦.      一.可选类型(重点内容)   1.什么是可选类型?        1.1在OC开 ...