http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1437
题意:
思路:
单调栈题。求出以每个数为区间最大值的区间范围即可。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = *1e5+; int n;
int a[maxn];
int sta[maxn];
int l[maxn], r[maxn];
int ans[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int top = ;
for(int i=;i<=n;i++)
{
while(top && a[sta[top]]>=a[i]) top--;
if(top==) l[i]=;
else l[i]=sta[top]+;
sta[++top]=i;
}
top = ;
for(int i=n;i>=;i--)
{
while(top && a[sta[top]]>a[i]) top--;
if(top==) r[i]=n;
else r[i]=sta[top]-;
sta[++top]=i;
}
for(int i=;i<=n;i++)
ans[r[i]-l[i]+]=max(ans[r[i]-l[i]+],a[i]);
for(int i=n-;i>=;i--)
ans[i]=max(ans[i],ans[i+]);
for(int i=;i<=n;i++)
printf("%d%c",ans[i],i==n?'\n':' ');
}
return ;
}