#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	vector <int> a(n), f(n);
	for (int i = 0; i < n; i ++ )
		cin >> a[i];
	stack <int> s;
	for (int i = n - 1; i >= 0; i -- ){
		while (s.size() && a[s.top()] <= a[i]) s.pop();
		if (s.size()) f[i] = s.top() + 1;
		s.push(i);
	}
	for (int i = 0; i < n; i ++ )
		cout << f[i] << " \n"[i == n - 1];
	return 0;
}

luogu 模板: https://www.luogu.com.cn/problem/P5788

posted on 2022-04-24 11:35  Hamine  阅读(13)  评论(0编辑  收藏  举报