#include
#include
#include
#include
using namespace std;
struct node
{
int x; //所在x下标
int y; //所在高度
int left_or_right;//是一个长方形的 左边=0 右边=1
node(int _x,int _y,int which)
{
x=_x;
y=_y;
left_or_right=which;
}
};
bool static cmp1(node a,node b)
{
return a.xright 按照下标排序
}
class my_heap
{
private:
priority_queue q1;
priority_queue q2; //两个最大堆
public:
void push(int _v)
{
q1.push(_v);
}
void erase(int _v) //任意节点删除
{
q2.push(_v);//在待删除堆中插入该值即可
}
void pop() //删除过程 首先
{
while(q1.top()==q2.top()) //如果q2的堆顶(那些被任意删除的元素)==q1的堆顶 不断一起弹出
{
q1.pop();
q2.pop();
}
q1.pop(); //最后弹出
}
int top() //获取最大最
{
while(q1.empty()==false &&q2.empty()==false && q1.top()==q2.top())
{
q1.pop();
q2.pop();
}
if(q1.empty())
return 0;
else
return q1.top();
}
bool empty() //当前堆是否为空
{
return q1.size()==0 || q1.size()==q2.size();
}
};
int main()
{
int n;
cin>>n;
int l,r,h;
vector node_arr;//存放关键点
for(int i=0;i
{
cin>>l>>r>>h;
node_arr.push_back(node(l,h,0));
node_arr.push_back(node(r,h,1)); //每个大楼都有两个关键节点
}
sort(node_arr.begin(),node_arr.end(),cmp1);
//初始化两个最大堆 以支持任意节点的删除
my_heap skyline;
int len=node_arr.size();
int height=0;//当前楼最大高度
int index=0;//当前最大高度的左起点
for(int i=0;i
{
if(node_arr[i].left_or_right==0) //左边节点
{
skyline.push(node_arr[i].y); //放入最大堆中
int now_height=skyline.top();//当前的最大高度
if(now_height>height) //新加入楼更高了
{
if(height>0 && node_arr[i].x>index)
cout<
//同时更新新的区间起点信息
index=node_arr[i].x;
height=node_arr[i].y;
}
}
else //遇到右边关键点
{
skyline.erase(node_arr[i].y);//删除该节点
if(skyline.top()
{
if(node_arr[i].x>index)
cout<
//更新区间的起点信息
index=node_arr[i].x;
height=skyline.top();
}
}
}
}