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

代码如下:

# 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. Installing Cygwin and Starting the SSH Daemon

    This chapter explains how to install Cygwin and start the SSH daemon on Microsoft Windows hosts. Thi ...

  2. IOS界面切换

    好吧!表示这几天要实现  phonegap 打开IOS原生界面,因此也查询了一些方案. 有如下几种: 第一种:navigationcontroller //进入下层 [self.navigationC ...

  3. <em>标签

    <em> 标签告诉浏览器把其中的文本表示为强调的内容.对于所有浏览器来说,这意味着要把这段文字用斜体来显示.

  4. How Android Draws Views

    https://developer.android.com/guide/topics/ui/how-android-draws.html

  5. char, signed char, and unsigned char in C++

    关于这三者的区别stackoverrflow里有一个答案是这样说的: 3.9.1 Fundamental types [basic.fundamental] 1 Objects declared as ...

  6. 利用 Postfix 抵擋垃圾信

    reject_unknown_client               //add 20151117

  7. Request的参数信息

    Request.ServerVariables["Url"] 返回服务器地址 Request.ServerVariables["Path_Info"] 客户端提 ...

  8. Extjs学习笔记(-):ComboBox联动

    http://www.cnblogs.com/wumin97136/archive/2007/12/24/1012720.html http://examples.ext.net/ http://ex ...

  9. 换个心境搞IT,在IT职场如何打拼?

    刚进入IT这行时,我也是从程序员做起.尤其是前两三个月里,那种感觉就像时时刻刻处于备战状态一样.我是一个在对自己的要求方面有洁癖的人,在没有任何经验的状态下,只有坚持苦干,把下发的每件编程任务做好,才 ...

  10. java学习第九天

    目标 异常(5个关键字 throw try catch finally throws ) 一.概念 异常: 非正常情况,例外.人为什么会生病?内因+外因.内因: 身体不够健壮—>锻炼身体增强体质 ...