本文最后更新于 105 天前,其中的信息可能已经有所发展或是发生改变。
https://www.luogu.com.cn/problem/P5788
#include<bits/stdc++.h>
using namespace std;
const int N = 10000010;
typedef long long LL;
typedef list<int>::iterator Iter;
list<int> L;
deque<int> dq;
queue<int> q;
stack<int> s;
// int a[N], ans[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n + 1, 0), ans(n + 1, 0);
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = n; i >= 1; i -- ) {
while (!s.empty() && a[s.top()] <= a[i]) s.pop();
if (s.empty()) ans[i] = 0;
else ans[i] = s.top();
s.push(i);
}
for (int i = 1; i <= n; i ++ ) cout << ans[i] << " ";
return 0;
}