0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 17:36:27 +00:00
OI-codes/Luogu/P5788/P5788.cpp

37 lines
581 B
C++

#include <iostream>
#include <stack>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e6 + 5;
int n, a[N], f[N];
std::stack<int> st;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i; i--) {
while (!st.empty() && a[st.top()] <= a[i]) st.pop();
f[i] = st.empty() ? 0 : st.top();
st.emplace(i);
}
for (int i = 1; i <= n; i++) {
cout << f[i] << ' ';
}
cout << endl;
return 0;
}