#include<bits/stdc++.h> #define IO ios::sync_with_stdio(0);cin.tie(0) #define endl 'n' #define MAXN 100005 #define pii pair<int, int> #define f first #define s second
usingnamespacestd;
int n; int h[MAXN], res[MAXN]; stack<pii> s;
signed() { IO; while (cin >> n) { for (int i = 0; i < n; i++) cin >> h[i]; memset(res, 0, sizeof(res)); s = stack<pii>(); for (int i = 0; i < n; i++) { while (!s.empty() && s.top().f < h[i]) s.pop(); res[i] += (s.empty() ? i : i - s.top().s); s.push({h[i], i}); } s = stack<pii>(); for (int i = n - 1; i >= 0; i--) { while (!s.empty() && s.top().f < h[i]) s.pop(); res[i] += (s.empty() ? n - i - 1 : s.top().s - i); s.push({h[i], i}); } for (int i = 0; i < n; i++) cout << res[i] + 1 << ' '; cout << endl; } return0; }
近期评论