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 ...
随机推荐
- .net core 监听性能,异常
https://www.cnblogs.com/laozhang-is-phi/p/10287023.html#autoid-2-2-0
- 使用redis实现生产者消费者模式
本次主要分享一下使用redis做缓存队列,实现生产者消费者模式. 首先先来看一下redis提供的列表操作接口.像ListRightPush就和符合队列先进先出的原则. 然后围绕这个列表已下单为例简要实 ...
- 二十二:制作app的时候超出部分不能滑动
给需要滑动的区域写以下样式(父级是浏览器) position: absolute; left: 0; right: 0; bottom: 0; top: 0; overflow-x: hidden; ...
- UVA -580 组合数学
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...
- IOS - UTF-8转码问题
2016.07.06 21:45* 字数 61 阅读 921评论 0喜欢 2 IOS中提供的转码. [utf8str stringByAddingPercentEscapesUsingEncoding ...
- p76泛函 有限维空间真子空间不可能在全空间稠密
连续函数 然后多项式函数是稠密的 多项式子空间是无穷维的 多项式空间就是在全体连续函数的线性空间中稠密 有限维子空间是闭的 多项式空间也不是有限维 2的地方说 有限维真子空间必不稠密 那是对的啊 有 ...
- 【转】redis-cluster安装配置
需要三台虚拟机(生产环境是3个物理机),分配静态IP.cluster中共6个节点.3主3从.本文中每个虚拟机上的redis端口:6379 6380. 需要注意的两点: 3个主节点分别位于3台虚拟机上, ...
- promise-笔记
promise 封装Promise var fs = require('fs') function pReadFile(filePath) { return new Promise(function ...
- 2 JAVA 项目名称前红色叹号如何解决
1 Java 项目前出现红色叹号Eclipse找不到项目需要的JAR包,可以在这里面解决: ① 右键点击项目,选择[Build Path].[Configure Build Path...] ② 在这 ...
- Azure系列2.1.1 —— BlobContainerPermissions
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...