60求调
查看原帖
60求调
707424
monkeys_King楼主2023/10/23 21:36
#include <bits/stdc++.h>
using namespace std;
const int N = 30000005;
int a[N] , n , h[N];
stack<int> s;
int main()
{
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; i++) scanf("%d" , &a[i]);
	for(int i = n ; i >= 1 ; i--)
	{
		while(!s.empty() && a[s.top()] < a[i]) s.pop();
		if(s.empty()) h[i] = 0;
		else h[i] = s.top();
		s.push(i);
	}
	for(int i = 1 ; i <= n ; i++) printf("%d " , h[i]);
	return 0;
}
2023/10/23 21:36
加载中...