讲道理我之前暂时跳过染色的题是因为总觉得有什么很高端的算法来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)的更多相关文章

  1. POJ 2528 Mayor's posters

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  2. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  3. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  4. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  5. poj 2528 (线段树+离散化)

    poj 2528 For each input data set print the number of visible posters after all the posters are place ...

  6. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  7. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  8. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  9. poj 2528 线段树区间修改+离散化

    Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...

随机推荐

  1. 【转】silverlight telerik RadGridView 列头显示其他控件

    <telerik:GridViewDataColumn DataMemberBinding="{Binding target_id}" IsFilterable=" ...

  2. 在Eclipse for mac中配置tomcat,使web项目自动部署到tomcat

    jdk.tomcat的配置就不多说了,网上一大堆. 一.发现问题 在eclipse中新建Dynamic Web Project,配置好本地的tomcat并写好代码后选择Run on Server,但运 ...

  3. 曲线参数化的Javascript实现(代码篇)

    在曲线参数化的Javascript实现(理论篇)中推出了曲线弧长积分的公式,以及用二分法通过弧长s来查找样条曲线上对应的u,再求Q(u)的值.弧长积分函数如下: ,其中-----公式1 Simpson ...

  4. Python学习之变量

    Python 变量 python不用事先声明变量,赋值过程中就包含了变量声明和定义的过程 用“=”赋值,左边是变量名,右边是变量的值 数字 整数 int_var = 1 长整数 long_var = ...

  5. 使用恶意USB设备解锁 Windows & Mac 锁屏状态

    NSA专业物理入侵设备——USB Armory,可解锁任意锁屏状态的下的Windows和Mac操作系统,含最新发布的Windows10.及较早的Mac OSX El Capitan / Maveric ...

  6. $("").click与onclick的区别

    onclick是绑定事件,click本身是方法作用是触发onclick事件,只要执行了元素的click()方法,下面示例 Html代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  7. 【转】 修改vs2010帮助文档(MSDN)路径

    VS2010的MSDN采用代理网页的方式,规定首次确定目录后不能更改本地Help Library的路径,只好手动变更路径 第一步: 先把MSDN装好,先装在C盘,默认的路径 第二步 现在我要把MSDN ...

  8. POJ 2481-树状数组

    题意:给定几个区间,判断该区间是其余区间的真子集个数. 分析:真子集即寻找x,y满足a(小于或等于x),b(大于或等于y)的区间.跟star-POJ2352很类似. 转化:star那个题目是x,y都是 ...

  9. 从零开始学习Node.js例子九 设置HTTP头

    server.js //basic server的配置文件 ; var server = require('./basicserver').createServer(); server.useFavI ...

  10. 黑马程序员:Java编程_IO流

    =========== ASP.Net+Android+IOS开发..Net培训.期待与您交流!=========== 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设 ...