問題の意味
nがこのグループの強度のx値群のクマサイズの高さのためのn個の値(複数の連続クマ)熊の高さの最小値を表します
X(1 <= xで<= n)が最大強度値を得るため
http://codeforces.com/contest/548/problem/D
考え
我々は左に最も遠いのうち最小値としてすべての数を処理し、右の単調それがグループxのすべての長さのために見つけることができ、スタックすることができ、インターバルの長さを伸ばすの数はイコールxが、その後、回答数が貢献している場合よりも大きく、 。
サンプルでは、我々は治療後に、それは確かにこのルールを持っていることが観察しました:
そして、あなたは〜の友人に係合することができます
コード
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int g[N],L[N],R[N],a[N],h[N],mx[N];
int main()
{
std::ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
a[n+1]=-1;
stack<int> st;
for(int i=1; i<=n; i++)
{
while(!st.empty()&&a[i]<=a[st.top()])
{
st.pop();
}
if(st.empty())
{
L[i]=1;
}
else
{
L[i]=st.top()+1;
}
st.push(i);
}
while(!st.empty()) st.pop();
for(int i=n; i>=1; i--)
{
while(!st.empty()&&a[i]<=a[st.top()])
st.pop();
if(st.empty())
{
R[i]=n;
}
else
R[i]=st.top()-1;
st.push(i);
}
/* for(int i=1; i<=n; i++)
{
cout<<L[i]<<" "<<R[i]<<" "<<endl;
}
cout<<endl;*/
for(int i=1; i<=n; i++)
h[R[i]-L[i]+1]=max(h[R[i]-L[i]+1],a[i]);
for(int i=n;i>=1;i--)
mx[i]=max(mx[i+1],h[i]);
for(int i=1;i<=n;i++)
{
printf("%d ",mx[i]);
}
puts("");
return 0;
}