题目分析:线段树区间更新+离散化

代码如下:

# include<iostream>
# include<cstdio>
# include<queue>
# include<vector>
# include<list>
# include<map>
# include<set>
# include<cstdlib>
# include<string>
# include<cstring>
# include<algorithm>
using namespace std;
# define LL long long const int N=10000;
const int INF=1<<30;
const double oo=1e20;
const double eps=1e-20; int x[N+5],y[N+5];
vector<int>v;
map<int,int>mp;
int lazy[N*8+5];
int tr[N*8+5];
set<int>s; void pushDown(int o,int l,int r)
{
if(lazy[o]!=-1){
lazy[o<<1]=lazy[o<<1|1]=lazy[o];
tr[o<<1]=tr[o<<1|1]=lazy[o];
lazy[o]=-1;
}
} void build(int o,int l,int r)
{
tr[o]=-1;
lazy[o]=-1;
if(l==r) return ;
int mid=l+(r-l)/2;
build(o<<1,l,mid);
build(o<<1|1,mid+1,r);
} void update(int o,int l,int r,int L,int R,int val)
{
if(L<=l&&r<=R){
tr[o]=lazy[o]=val;
}else{
pushDown(o,l,r);
int mid=l+(r-l)/2;
if(L<=mid) update(o<<1,l,mid,L,R,val);
if(R>mid) update(o<<1|1,mid+1,r,L,R,val);
}
} void query(int o,int l,int r)
{
if(l==r){
if(tr[o]!=-1) s.insert(tr[o]);
}else{
pushDown(o,l,r);
int mid=l+(r-l)/2;
query(o<<1,l,mid);
query(o<<1|1,mid+1,r);
}
} int solve(int m,int n)
{
build(1,1,m);
for(int i=0;i<n;++i){
update(1,1,m,mp[x[i]],mp[y[i]],i);
}
s.clear();
query(1,1,m);
return s.size();
} int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
mp.clear();
v.clear();
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%d%d",x+i,y+i);
v.push_back(x[i]);
v.push_back(y[i]);
}
sort(v.begin(),v.end());
int len=unique(v.begin(),v.end())-v.begin();
for(int i=0;i<len;++i)
mp[v[i]]=i+1;
printf("%d\n",solve(len,n));
}
return 0;
}

  

POJ-2528 Mayor's posters (线段树区间更新+离散化)的更多相关文章

  1. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

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

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

  3. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

  4. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  5. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  6. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

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

  7. POJ 2528 Mayor’s posters (线段树段替换 && 离散化)

    题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...

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

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

  9. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  10. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

随机推荐

  1. 利用K2和Microsoft Dynamics CRM构建业务App的5大理由

    Microsoft Dynamics CRM提供了一个绝佳的客户关系管理平台,使您能够创建各种以客户为中心的解决方案.然而,通过将K2的企业业务流程功能与Microsoft Dynamics CRM相 ...

  2. xlistview的(java)

    package com.bwie.xlistviews; import java.text.SimpleDateFormat;import java.util.Date; import com.bwi ...

  3. 今年plan,做好四件事情

    写代码, 写博客, 学英语, 锻炼身体.

  4. Map-Reduce的工作机制

    Mapper “Map-Reduce”的思想就是“分而治之” Mapper负责“分”,即把复杂的任务分解为若干个“简单的任务”而执行 “简单的任务”有几个意思:1.数据或计算规模相对于原任务要大大缩小 ...

  5. flash 和 第三方程序交互

    一.flash 端 修改 1.flash cs6  修改脚本 为as3 2.修改 按钮 实例 名 (不是sprite列表中的名字  实例名称 和这个名字 是2个) 3.时间轴上 添加代码 当前选择 A ...

  6. 管理Fragment

    转载原地址:http://blog.csdn.net/harvic880925/article/details/44927375 相关文章: 1.<Fragment详解之一——概述>2.& ...

  7. angularJs 自定义服务 provide 与 factory 的区别

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  8. Ubuntu 14.10 下安装navicat

    1 下载navicat,网址http://www.navicat.com.cn/download,我下载的是navicat111_premium_cs.tar.gz 2 解压到合适的位置 3 进入解压 ...

  9. javascript笔记5-BOM

    Javascript应用的平台很多,不仅仅针对Web.在Web中使用Javascript,BOM(browser object model,浏览器对象模型)是核心. BOM提供了很多对象,用于访问浏览 ...

  10. H5实现俄罗斯方块(一)

    这几天一直忙于公司的项目,涉及到流程问题,(有时间会写成博客的)...一直没有更新... 为了更加巩固js的基础,自己封装类似于JQuery的操作库来对dom进行操作. 一:前度页面的绘制. < ...