POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化
代码如下:
# 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 (线段树区间更新+离散化)的更多相关文章
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- POJ 2528 Mayor’s posters (线段树段替换 && 离散化)
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
随机推荐
- JavaScript 数组方法和属性
一. 数组对象的操作方法 1. 数组的创建 2.prototype属性 返回对象原型的引用,prototype属性时object共有的. objectName.prototype,其中objectNa ...
- web安全 -- 常见攻击方法及预防措施
一.sql注入 sql注入,是指攻击者在猜测出服务器上要执行sql后:通过输入数据,拼接原来要执行的sql而形成新的sql:从而到达改变原来查询的意义的目的. -- 原来sql select xxx ...
- HTTPS Everywhere – 保障隐私和信息安全的利器
HTTPS Everywhere 是一款 Chrome 扩展程序,对于支持 HTTPS 的网站默认打开 HTTPS 加密传输来保障信息安全(HTTPS 介绍). HTTPS Everywhere 受到 ...
- Browser GetImage
using Microsoft.Win32; using System; using System.ComponentModel; using System.Drawing; using System ...
- poj2769 暴力
//Accepted 208 KB 157 ms //纯暴力 //vis数组初始化时要用多少设置多少,不然TLE #include <cstdio> #include <cstrin ...
- 转载--Ubuntu设置环境变量
Ubuntu设置环境变量并立即生效(以Ubuntu12.04为例) 标签: UbuntuLinux环境变量 2013-09-12 19:04 9961人阅读 评论(1) 收藏 举报 分类: Ubun ...
- hdoj-2031
#include "stdio.h"#include "stdlib.h"int main(){ char a[]={'0','1','2','3','4',' ...
- 5、网页制作Dreamweaver(JS的初步运用)
JAVASCRIPT *放在头部也可以读取(最先读取头部) 表单提交时会自动刷新网页,最好关掉 写法: 1.输出 <script> document.write("hello w ...
- asp.net ToString()格式汇总
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...
- 一个简单的解决方法:word文档打不开,错误提示mso.dll模块错误。
最近电脑Word无故出现故障,无法打开,提示错误信息如下: 问题事件名称: APPCRASH应用程序名: WINWORD.EXE应用程序版本: 11.0.8328.0应用程序时间戳: 4c717ed1 ...