很裸的单调栈。。
计算出每个数作为最小值的区间最大长度len,然后更新ans[len],最后倒着更新一遍ans[]就好了。
很坑地要加读优输优。
/*************************************************************
Problem: 51nod 1437 迈克步
User: bestFy
Language: C++
Result: Accepted
Time: 312 ms
Memory: 5596 KB
Submit_Time: 2017/11/15 19:42:41
*************************************************************/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
typedef long long LL;
inline LL read()
{
char ch = getchar(); LL x = 0; int op = 1;
for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1;
for (; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
return op*x;
}
inline void writeAbs(LL a)
{
if (a >= 10) writeAbs(a/10);
putchar('0'+a%10);
}
inline void write(LL a)
{
if (a < 0) putchar('-');
writeAbs(abs(a));
}
inline void writeln(LL a)
{
write(a); puts("");
}
const int N = 200010;
int n, top;
int a[N], st[N], ans[N], L[N], R[N];
int main()
{
n = read();
for (int i = 1; i <= n; i ++) a[i] = read();
st[top = 0] = 0;
for (int i = 1; i <= n; i ++){
while (top && a[st[top]] > a[i]) top --;
L[i] = st[top]; st[++ top] = i;
}
st[top = 0] = n+1;
for (int i = n; i >= 1; i --){
while (top && a[st[top]] >= a[i]) top --;
R[i] = st[top]; st[++ top] = i;
}
for (int i = 1; i <= n; i ++)
ans[R[i]-L[i]-1] = max(ans[R[i]-L[i]-1], a[i]);
for (int i = n; i >= 1; i --){
ans[i] = max(ans[i+1], ans[i]);
}
for (int i = 1; i <= n; i ++) write(ans[i]), putchar(' ');
return 0;
}