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

代码如下:

# 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. [Swift2.0系列]Defer/Guard 基础语法

    1.Defer Swift2.0中加入了defer新语法声明.defer译为延缓.推迟之意.那么在Swift2.0中它将被应用于什么位置呢?比如,读取某目录下的文件内容并处理数据,你需要首先定位到文件 ...

  2. how to reset mac root password

    Reset 10.5 Leopard & 10.6 Snow Leopard password Power on or restart your Mac. At the chime (or g ...

  3. 支持.NET和移动设备的XLS读写控件XLSReadWriteII下载地址及介绍

    原文来自龙博方案网http://www.fanganwang.com/product/3085转载请注明出处 读写任何单元值 数字型.字符型.布尔型以及错误型.但是你了解日期和时间型单元吗?在Exce ...

  4. SrcollView分页加载数据(MainActivity)

    package com.baidu.mylistscroll; import java.util.ArrayList;import java.util.List; import com.baidu.a ...

  5. Jquery实现的Tabs标签页

    效果图: HTML: <div class="tabs"> <ul id="tabs"> <li class="tab- ...

  6. SQL Server CONVERT() 函数(转)

    定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用不同的格式显示日期/时间数据. 语法 CONVERT(data_type(length),dat ...

  7. 提示错误#165 too few argument in function call

    调用函数时,参数个数少于函数定义.检查一下函数定义和参数调用,两个要一致.

  8. java多线程的协作

    java多线程之间相互协作,主要有join,  yield,  interupt(),  sleep,  wait,  notify,  notifyAll; join: 在一个线程A的代码里面调用另 ...

  9. 对于我的linux常用命令的说明

    我所列出的linux常用命令中的选项并不是全部的选项,是一些我们经常用到的linux命令及选项

  10. 对前端mvc的认识和思考

    现在,我们经常都可以看到复杂的JavaScript应用程序,由于这些应用程序变得越来越复杂,一长串的jQuery回调语句或者通过应用程序在 各个状态执行不同的函数调用,这些做法都会变得无法再让人接受, ...