79分……
查看原帖
79分……
1284034
__lihaoyu68__楼主2024/6/22 15:54
#include <bits/stdc++.h>
using namespace std;
int h[200000], n, now, nxt[200000], pre[200000], w[200000];
long long ans[200000], t;
int main() {
	cin >> n;
	h[0] = h[n + 1] = 0x7f7f7f7f;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> h[i];
		pre[i] = i - 1;
		nxt[i] = i + 1;
		if (h[i] < h[now]) now = i;
	}
	while (pre[now] != 0 || nxt[now] != n + 1) {
		if (h[now] > h[pre[now]]) {now = pre[now]; continue;}
		if (h[now] > h[nxt[now]]) {now = nxt[now]; continue;}
		ans[now] = t + w[now];
		t += w[now] * 1ll * (min(h[pre[now]], h[nxt[now]]) - h[now]);
		nxt[pre[now]] = nxt[now], pre[nxt[now]] = pre[now];
		if (h[pre[now]] > h[nxt[now]]) w[nxt[now]] = w[now] + w[nxt[now]], now = nxt[now];
		else w[pre[now]] = w[now] + w[pre[now]], now = pre[now];
	}
	ans[now] = t + w[now];
	for (int i = 1; i <= n; i++) cout << ans[i] << endl;
	return 0;
}

为什么每次绿题以上我都要求助qwq

2024/6/22 15:54
加载中...