D. Mike and Feet
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.

A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.

Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.

Input

The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.

The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.

Output

Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.

Examples
input
10
1 2 3 4 5 4 3 2 1 6
output
6 4 4 3 3 2 2 1 1 1 

题意:给你一个长度为n的数列 求长度为x x取值(1,n)  的区段最小值的最大值

题解:求以a[i]为最小值的区段的左界右界;

dp[r[i]-l[i]+1]=max(dp[r[i]-l[i]+1],a[i]) 倒序取max得到每个长度的答案;

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
int a[];
int l[];
int r[];
int ans[];
int dp[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
a[]=-;
a[n+]=-;
l[]=;
for(int i=; i<=n; i++) //关键********
{
int temp=i-;
while(a[temp]>=a[i])//维护一个递增的序列
temp=l[temp]-;
l[i]=temp+;
}
r[n]=n;
for (int i=n-; i>=; i--)
{
int temp=i+;
while(a[temp]>=a[i])
temp=r[temp]+;
r[i]=temp-;
}
for(int i=;i<=n;i++)
dp[r[i]-l[i]+]=max(dp[r[i]-l[i]+],a[i]);
int res=;
for(int i=n;i>=;i--){
res=max(res,dp[i]);
ans[i]=res;
}
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
return ;
}

最新文章

  1. 昨天写支付接口时遇到支付接口返回数据接收地址,session数据丢失(或者说失效)的问题
  2. Autoit3 获取WinForm下的ToolTip
  3. JNI系列——PassData
  4. flash builder4.7bug
  5. 调整iFrame高度
  6. sql必知必会(第四版) 学习笔记
  7. Ubuntu上安装Maven Eclipse以及配置
  8. Ext.Ajax.request
  9. Java异常处理示例
  10. Batch Normalization原理
  11. Java开发之@PostConstruct执行顺序
  12. highcharts echarts比较
  13. [k8s]kube-dns架构图解
  14. mysql 事件 按月分表
  15. ---转载---phython资料
  16. LintCode: Single Number II
  17. wprintf或_tprintf不显示中文和乱码问题
  18. svn错误:Can't convert string from 'UTF-8' to native encoding
  19. eclipse逆向生成实体类注解方式或者xml方式
  20. gulp#4.0 Did you forget to signal async completion?

热门文章

  1. mac安装pkg 一直“正在验证” 卡着
  2. Java如何调用shell脚本的
  3. ES6的新特性(13)——Symbol
  4. 《linux内核与分析》第三周
  5. 【线段树维护复杂状态】Ryuji doesn&#39;t want to study
  6. Struts2:&lt;s:action&gt;的使用
  7. linux应用自启动配置
  8. Delphi定位TDataSet数据集最后一条记录
  9. Linux 下定位java应用 cpu高的原因(转)
  10. display:table的几个妙用:垂直居中、浮动……