P1904 天际线(离散化)

#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<cstring>
#define int long long
const int N = 1e6+5;
using namespace std;
char* p1, * p2, buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read()
{
	int x = 0, f = 1;
	char ch = nc();
	while (ch < 48 || ch>57)
	{
		if (ch == '-')
			f = -1;
		ch = nc();
	}
	while (ch >= 48 && ch <= 57)
		x = x * 10 + ch - 48, ch = nc();
	return x * f;
}
int a[N], b[N], c[N],f[N],h[N],ans[N];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int cnt = 0;
	int k = 0;
	while (cin >> a[++cnt] >> h[cnt] >> b[cnt]) {
		c[++k] = a[cnt];
		c[++k] = b[cnt];
	}
	sort(c + 1, c + 1 + k);
	for (int i = 1; i <= cnt; i++) {
		a[i] = lower_bound(c + 1, c + 1 + k, a[i])-c;
		b[i] = lower_bound(c + 1, c + 1 + k, b[i])-c;
		for (int j = a[i]; j < b[i]; j++)f[j] = max(f[j], h[i]);
	}
	int x = 1;
	ans[1] = c[1];
	for (int i = 2; i <= k; i++) {
		if (f[i] != f[i - 1]) {
			ans[++x] = f[i-1];
			ans[++x] = c[i];
		}
	}
	for (int i = 1; i <= x; i++)cout << ans[i] << " ";
	cout << 0;
	return 0;
}
posted @   郭轩均  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示