2022-10-28 14:04:10 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <stack>
|
2021-08-03 00:19:50 +00:00
|
|
|
|
2022-10-28 14:04:10 +00:00
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
const char endl = '\n';
|
2021-08-03 00:19:50 +00:00
|
|
|
|
2022-10-28 14:04:10 +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);
|
2022-10-28 14:04:10 +00:00
|
|
|
cin.tie(nullptr);
|
|
|
|
|
2021-08-03 00:19:50 +00:00
|
|
|
cin >> n;
|
2022-10-28 14:04:10 +00:00
|
|
|
|
2021-08-03 00:19:50 +00:00
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
cin >> a[i];
|
|
|
|
}
|
2022-10-28 14:04:10 +00:00
|
|
|
|
|
|
|
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();
|
2022-10-28 14:04:10 +00:00
|
|
|
st.emplace(i);
|
2021-08-03 00:19:50 +00:00
|
|
|
}
|
2022-10-28 14:04:10 +00:00
|
|
|
|
2021-08-03 00:19:50 +00:00
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
cout << f[i] << ' ';
|
|
|
|
}
|
2022-10-28 14:04:10 +00:00
|
|
|
|
2021-08-03 00:19:50 +00:00
|
|
|
cout << endl;
|
2022-10-28 14:04:10 +00:00
|
|
|
|
2021-08-03 00:19:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|