0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 17:32:01 +00:00
OI-codes/Luogu/P5788/P5788.cpp

37 lines
581 B
C++
Raw Normal View History

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