蒟蒻求助qaq
  • 板块P1382 楼房
  • 楼主Nick_zheng
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/9 22:51
  • 上次更新2024/10/10 13:30:50
查看原帖
蒟蒻求助qaq
685909
Nick_zheng楼主2024/10/9 22:51

所以这是水过去了吗

看起来时间复杂度没问题a

提交记录

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
map<int,pii> mp;
queue<int> an;
priority_queue<pii> q;
void add(int h,int l,int r)
{
	if(l==r)
	{
		return;
	}
	if(mp[l].first)
	{
		if(mp[l].second>=r)
		{
			if(mp[l].first>=h)
			{
				return;
			}
			else
			{
				add(mp[l].first,r,mp[l].second);
				mp[l]={h,r};
			}
		}
		else
		{
			if(mp[l].first<=h)
			{
				mp[l]={h,r};
			}
			else
			{
				add(h,mp[l].second,r);
			}
		}
	}
	else
	{
		mp[l]={h,r};
	}
}
signed main()
{
	int n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		int h,l,r;
		scanf("%lld %lld %lld",&h,&l,&r);
		add(h,l,r);
		if(!mp[r].first)
		{
			mp[r].first=0;
			mp[r].second=0x3f3f3f3f;
		}
	}
	int lash=0;
	for(auto i:mp)
	{
//		if(i.second.second!=0x3f3f3f3f)
//		{
			q.push(i.second);
//		}
//		printf("%lld %lld %lld\n",i.first,i.second.first,i.second.second);
		while(q.size()&&q.top().second<=i.first)
		{
			q.pop();
		}
		if(q.size())
		{
//			printf("%lld %lld\n",q.top().first,q.top().second);
			if(lash==q.top().first)
			{
				continue;
			}
//			printf("%lld %lld\n%lld %lld\n",i.first,lash,i.first,q.top().first);
			an.push(i.first);
			an.push(lash);
			an.push(i.first);
			an.push(q.top().first);
			lash=q.top().first;
		}
	}
	printf("%lld\n",((int)(an.size()))>>1);
	while(an.size())
	{
		printf("%lld ",an.front());
		an.pop();
		printf("%lld\n",an.front());
		an.pop();
	}
 	return 0;
}
2024/10/9 22:51
加载中...