D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询
题意 贴海报 最后可以看到多少海报
思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入就行了
注:参考了上海全能王csl的博客!
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
#define X first
#define Y second
const int maxn=+;
pair<int,int>a[maxn*];
vector<int>v;
struct Node{
int l,r;
int col;
int lazy;
void update(int x){
col=x;
lazy=x;
}
}tree[maxn*];
bool vis[maxn*];
/*void push_up(int x){
if(tree[x<<1].col!=tree[x<<1|1].col||tree[x<<1].col==-1||tree[x<<1|1].col==-1)tree[x].col=-1;
}*/ void build(int x,int l,int r){
tree[x].l=l,tree[x].r=r;
tree[x].col=-;
if(l==r){
return ;
}
else {
int mid=l+r>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
}
} void push_down(int x){
if(tree[x].col==-)return;
tree[x<<].col=tree[x<<|].col=tree[x].col;
tree[x].col=-;
}
void update(int x,int l,int r,int val){
int L=tree[x].l,R=tree[x].r;
if(l<=L&&R<=r){
tree[x].col=val;
return ;
}
else {
push_down(x);
int mid=(L+R)>>;
if(l<=mid)update(x<<,l,r,val);
if(mid<r)update(x<<|,l,r,val);
// pudh_up(x);单点查询不需要合并
}
}
long long query(int x,int a){
int L=tree[x].l,R=tree[x].r;
if(L==R)return tree[x].col;
push_down(x);
int mid=L+R>>;
if(mid>=a)query(x<<,a);
else if(mid<a)query(x<<|,a);
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
memset(vis,,sizeof(vis));
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&a[i].X,&a[i].Y);
v.push_back(a[i].X);
v.push_back(a[i].Y);
v.push_back(a[i].Y+);
}
sort(v.begin(),v.end());
int num=unique(v.begin(),v.end())-v.begin();
for(int i=;i<n;i++){
a[i].X = lower_bound(v.begin(), v.begin() + num, a[i].X) - v.begin() + ;
a[i].Y = lower_bound(v.begin(), v.begin() + num, a[i].Y) - v.begin() + ;
}
build(,,num);
for(int i=;i<n;i++){
update(,a[i].X,a[i].Y,i+);
}
int ans=;
for(int i=;i<=num;i++){
int col=query(,i);
// cout<<col<<endl;
if(col!=-&&vis[col]==){
vis[col]=;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}
D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询的更多相关文章
- HDU 5861 Road(线段树 区间修改 单点查询)
Road Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- POJ - 2528 Mayor's posters (离散化+线段树区间修改)
https://cn.vjudge.net/problem/POJ-2528 题意 给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张? 分析 ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- POJ 3468 A Simple Problem with Integers(线段树区间修改及查询)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- hdu 1166 敌兵布阵 线段树区间修改、查询、单点修改 板子题
题目链接:敌兵布阵 题目: C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视 ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
随机推荐
- git学习之时光穿梭机
"x"修改readme.txt文件,改成如下内容: Git is a distributed version control system. Git is free softwar ...
- 解决React通过ajax加载数据更新页面不加判断会报错的问题
通过AJAX加载数据是一个很普遍的场景.在React组件中如何通过AJAX请求来加载数据呢?首先,AJAX请求的源URL应该通过props传入:其次,最好在componentDidMount函数中加载 ...
- Python入门-格式化输出
需求:将用户的姓名.年龄.工作.爱好 ,然后打印成以下格式: ------------ Info of Tom ------ Name : Tom Age : 22 Job : Teacher Hob ...
- Survey项目总结
1.Ioc深入理解 Inverse of control org.springframework.scheduling.quartz.SchedulerFactoryBean org.mybatis. ...
- Linux sed使用方法
目录 sed处理流程 测试数据 sed命令格式 sed命令行格式 行定位 定位1行 定位区间行(多行) 定位某一行之外的行 定位有跨度的行 操作命令 -a (新增行) -i(插入行) -c(替代行) ...
- 使用 Drools 和 JPA & Drools show case in docker hub
使用 Drools 和 JPA 实现持续的实时数据分析https://www.ibm.com/developerworks/cn/java/j-drools5/index.html Drools - ...
- C#实现,C++实现,JS实现 阿拉伯数字金额转换为中文大写金额
推荐在线编译器 ideone 1. C#实现 :带有负数处理 //把数字金额转换成中文大写数字的函数 //带有负值处理 function changeNumMoneyToChinese(money) ...
- Oracle NVL空值处理函数
--NVL空值处理函数 --需求:显示价格表中业主类型ID为1的价格记录 如果上限值为null,则显示9999999 ) from dual; select * from t_pricetable ) ...
- python爬虫之初始scrapy
简介: Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 其最初是为了 页面抓取 (更确切来说, 网络抓取 )所设 ...
- WPF程序中App.Config文件的读与写
WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就 ...