题意 贴海报 最后可以看到多少海报

思路 :离散化大区间  其中[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 离散化+线段树 区间修改单点查询的更多相关文章

  1. HDU 5861 Road(线段树 区间修改 单点查询)

    Road Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  2. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  3. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  4. POJ - 2528 Mayor's posters (离散化+线段树区间修改)

    https://cn.vjudge.net/problem/POJ-2528 题意 给定一些海报,可能相互重叠,告诉你每个海报的宽度(高度都一样的)和先后叠放顺序,问没有被完全盖住的有多少张? 分析 ...

  5. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 ...

  6. 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 ...

  7. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  8. hdu 1166 敌兵布阵 线段树区间修改、查询、单点修改 板子题

    题目链接:敌兵布阵 题目: C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视 ...

  9. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

随机推荐

  1. 【C#复习总结】多线程编程

    1 基本概念 前一篇文章做了铺垫,详见:http://www.cnblogs.com/mhq-martin/p/9035640.html 2 多线程 多线程的优点:可以同时完成多个任务:可以使程序的响 ...

  2. 使用PHPExcel将数据导出至Excel

    安装类库 从GitHub上下载PHPExcel类库 地址:https://github.com/PHPOffice/PHPExcel 解压后将Classes文件夹移动到ThinkPHP的extend目 ...

  3. 朱晔和你聊Spring系列S1E5:Spring WebFlux小探

    阅读PDF版本 本文会来做一些应用对比Spring MVC和Spring WebFlux,观察线程模型的区别,然后做一下简单的压力测试. 创建一个传统的Spring MVC应用 先来创建一个新的web ...

  4. BAT美团滴滴java面试大纲(带答案版)之三:多线程synchronized

    继续面试大纲系列文章. 从这一篇开始,我们进入ava编程中的一个重要领域---多线程!多线程就像武学中对的吸星大法,理解透了用好了可以得道成仙,俯瞰芸芸众生:而滥用则会遭其反噬. 在多线程编程中要渡的 ...

  5. stl stack用法

    栈后进先出 #include<iostream> #include<algorithm> #include<cstdio> #include<stack> ...

  6. Python学习第十五篇——类继承和类实例化

    学习Python类时,我们明白了类的本质,以及所谓的面向对象编程思想强调的对事物本身的属性,我们对某一类事物进行描述——采用了很多方法,这些方法描述了类的属性(比如猫科动物的眼睛,四肢,是否哺乳类等等 ...

  7. Linux系统mysql使用(二)

    一.查看某数据库的表 # 假设此时数据库名为hiveuse hive; show tables;

  8. 分布式Tomcat session会话Sticky Sessions问题

    分布式session会话Sticky Sessions - tomcat_baby的专栏 - CSDN博客https://blog.csdn.net/tomcat_baby/article/detai ...

  9. [服务器]Gartner:2018年第四季度全球服务器收入增长17.8% 出货量增长8.5%

    Gartner:2018年第四季度全球服务器收入增长17.8% 出货量增长8.5% Gartner 是不是也是花钱买榜的主啊.. 简单看了一下 浪潮2018Q4的营收18亿刀 (季度营收110亿人民币 ...

  10. 补充:pyhton 2 和3中的beyts类型

    在python2里,bytes == str python2里还有个单独的类型是unicode , 把字符串解码后,就会变成unicode. 既然python2中byets == str,那为什么还要 ...