用单调栈计算出一个数字, 左边第一个比他小的数字的位置, 右边比第一个他小的数字的位置, 然后len = r[i] - l[i] +1. ans[len] = max(ans[len], a[i])
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int l[maxn], r[maxn], ans[maxn], a[maxn], q[maxn];
int main()
{
int n;
cin>>n;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
int i = , st = ;
while(i<=n) {
while(st&&a[q[st-]]>a[i]) {
r[q[st-]] = i-;
st--;
}
q[st++] = i;
i++;
}
while(st) {
r[q[st-]] = n;
st--;
}
i = n;
while(i>=) {
while(st&&a[q[st-]]>a[i]) {
l[q[st-]] = i+;
st--;
}
q[st++] = i;
i--;
}
while(st) {
l[q[st-]] = ;
st--;
}
memset(ans, , sizeof(ans));
for(int i = ; i<=n; i++) {
int len = r[i]-l[i]+;
if(ans[len]<a[i]) {
ans[len] = a[i];
}
}
for(i = n; i>=; i--) {
if(ans[i]>=ans[i-])
ans[i-] = ans[i];
}
for(int i = ; i<=n; i++) {
printf("%d ", ans[i]);
}
}