题目描述

离散化,线段树维护区间修改,发现询问都是单点的\(max\),不妨把标记留在点上,不用下传,查询时取个\(max\)就可以了

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define lc (p<<1)
#define rc (p<<1|1)
using namespace std; const int MAXN=400010;
const int MAXM=1600010; inline int read(){
int x=0,f=1; char c=getchar();
while(c<'0'){ if(c=='-') f=-1; c=getchar(); }
while(c>='0') x=x*10+c-'0',c=getchar();
return x*f;
} int n,x[MAXN],cnt,num; struct Data{
int l,r,h;
} a[MAXN]; map<int,int> Map; int tree[MAXM],rev[MAXN]; inline void update(int L,int R,int h,int p=1,int l=1,int r=num){
if(L<=l&&r<=R){
tree[p]=max(tree[p],h);
return;
}
int mid=(l+r)>>1;
if(L<=mid) update(L,R,h,lc,l,mid);
if(R>mid) update(L,R,h,rc,mid+1,r);
} inline int query(int x,int p=1,int l=1,int r=num){
if(l==r) return tree[p];
int mid=(l+r)>>1,ans=tree[p];
if(x<=mid) ans=max(ans,query(x,lc,l,mid));
else ans=max(ans,query(x,rc,mid+1,r));
return ans;
} inline bool cmp(Data x,Data y){
if(x.l!=y.l)
return x.l<y.l;
return x.r<y.r;
} int ansx[MAXN],ansy[MAXN],ansnum; int main(){
n=read();
for(int i=1;i<=n;++i)
a[i].h=read(),a[i].l=read(),a[i].r=read(),--a[i].r;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;++i){
x[++cnt]=a[i].l;
x[++cnt]=a[i].l+1;
x[++cnt]=a[i].r;
x[++cnt]=a[i].r+1;
}
x[0]=x[1]-1;
sort(x+1,x+1+cnt);
for(int i=1;i<=cnt;++i)
if(x[i]!=x[i-1]) Map[x[i]]=++num,rev[num]=x[i];
++num;
for(int i=1;i<=n;++i)
update(Map[a[i].l],Map[a[i].r],a[i].h);
int last=0;
for(int i=1;i<=num;++i){
int tmp=query(i);
if(tmp!=last){
if(tmp>last){
ansx[++ansnum]=rev[i],ansy[ansnum]=last;
ansx[++ansnum]=rev[i],ansy[ansnum]=tmp;
}
else{
ansx[++ansnum]=rev[i-1]+1,ansy[ansnum]=last;
ansx[++ansnum]=rev[i-1]+1,ansy[ansnum]=tmp;
}
last=tmp;
}
}
printf("%d\n",ansnum);
for(int i=1;i<=ansnum;++i)
printf("%d %d\n",ansx[i],ansy[i]);
return 0;
}

【luoguP1382】楼房的更多相关文章

  1. AC日记——楼房 codevs 2995

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 地平线(x轴)上有n个矩(lou ...

  2. Bzoj2957 楼房重建

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1516  Solved: 723[Submit][Status][Discuss] Descripti ...

  3. 【清华集训】楼房重建 BZOJ 2957

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  4. 扫描线+堆 codevs 2995 楼房

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 地平线(x轴)上有n个矩(lou)形(fan ...

  5. BZOJ 2957 楼房重建

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  6. [BZOJ 2957]楼房重建(THU2013集训)(分块思想)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 分析: 首先明确问题,对于每栋楼房的斜率K=H/X,问题就是问有多少个楼房的K比前面所有 ...

  7. bzoj 2957: 楼房重建 线段树

    2957: 楼房重建 Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 小A的楼房外有一大片施 ...

  8. [bzoj2957][楼房重建] (线段树)

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  9. 【题解】Luogu P4198 楼房重建

    原题传送门 根据斜率来建线段树,线段树维护区间最大斜率以及区间内能看见的楼房的数量(不考虑其他地方的原因,两个节点合并时再考虑) 细节见程序 #include <bits/stdc++.h> ...

随机推荐

  1. CountDownLatch 一个复杂的例子

    CountDownLatch复杂点的例子 public class CountDownLatchTest2 { private static Random random = new Random(Sy ...

  2. python]用eval强制将字符串转换为字典变量时候出错:NameError: name 'null' is not defined[python]用eval函数 字符串转dict

    本博客已搬家至个人网站 在路上 - On the way 下面的 技术 分类. 你可以通过点击 更新帖子 [已解决]Python中,用eval强制将字符串转换为字典变量时候出错:NameError: ...

  3. Kubectl 的替代品:kubeman

    周末闲逛 Twitter 时,发现一个很有意思的小工具叫 kubeman,野心倒是不小,励志成为 kubectl 的替代品,用于实时监控和管理 kubernetes 集群,还可以调试与 Istio 相 ...

  4. python爬虫—爬取英文名以及正则表达式的介绍

    python爬虫—爬取英文名以及正则表达式的介绍 爬取英文名: 一.  爬虫模块详细设计 (1)整体思路 对于本次爬取英文名数据的爬虫实现,我的思路是先将A-Z所有英文名的连接爬取出来,保存在一个cs ...

  5. Lock+Condition实现机制

    前言:大部分多线程同步场景,在功能和性能层面,synchronized可以满足,少部分场景Lock可以满足,dubbo的源码也符合这个比例,需要使用到Condition的场景极少,整个dubbo源码中 ...

  6. Lisp : (quote) code is data (eval) data as code

  7. js 数组去重总结

    es6 set ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. let arr = [1,2,3,4,3,2,3,4,6,7,6]; let unique = ...

  8. PAT 1022D进制的A+B

    PAT 1022D进制的A+B 输入两个非负 10 进制整数 A 和 B (≤2​30−1),输出 A+B 的 D (1<D≤10)进制数. 输入格式: 输入在一行中依次给出 3 个整数 A.B ...

  9. Web Api 模型绑定 一

    [https://docs.microsoft.com/zh-cn/aspnet/core/web-api/?view=aspnetcore-2.2]1.模型绑定 简单模型绑定针对简单类型(如stri ...

  10. js中面向对象(创建对象的几种方式)

    1.面向对象编程(OOP)的特点: 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有的对象下继承出新的对象 多态:多对象的不同形态 注:本文引用于 http://www.cnblogs. ...