B. Mike and Feet

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/547/problem/B

Description

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.

Sample Input

10
1 2 3 4 5 4 3 2 1 6

Sample Output

6 4 4 3 3 2 2 1 1 1 

HINT

题意

给你一个堆数,对于(1,n)长度,让你找到线段的最小值的最大值是多少

题解:

用一个类似单调栈的思想,处理以这个点为最小值可以往左右延伸多少,然后乱搞一下就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[maxn];
int dp[maxn];
int l[maxn];
int r[maxn];
int main()
{
//test;
int n=read();
for(int i=;i<=n;i++)
a[i]=read();
a[]=-,a[n+]=-; for(int i=;i<=n;i++)
{
int j=i-;
while(a[j]>=a[i])j=l[j];
l[i]=j;
}
for(int i=n;i>=;i--)
{
int j=i+;
while(a[j]>=a[i])j=r[j];
r[i]=j;
}
for(int i=;i<=n;i++)
{
int len=r[i]-l[i]-;
dp[len]=max(dp[len],a[i]);
}
for(int i=n-;i>=;i--)
dp[i]=max(dp[i+],dp[i]);
for(int i=;i<=n;i++)
cout<<dp[i]<<" ";
}
10
1 2 3 4 5 4 3 2 1 6

最新文章

  1. Hadoop集群datanode磁盘不均衡的解决方案
  2. 结合nodejs开发aspnet5项目
  3. gulp进阶构建项目由浅入深
  4. G面经prepare: Straight Partition of A Deck of Cards
  5. 关于enum的那些事儿
  6. jQuery Validate 插件[表单验证]
  7. Android(java)学习笔记98:关于string类型的面试题
  8. zepto源码研究 - ajax.js($.ajaxJSONP 的分析)
  9. 捷易拍与springMVC系统结合
  10. 激活工具 – Microsoft Toolkit 2.4.7
  11. c,assert 宏的实现
  12. CVE-2015-0057 POC构造 &amp; 利用分析(2015.7)
  13. SpringMVC的视图解析器
  14. 关于MATLAB处理大数据坐标文件201762
  15. oracle如何连接别人的数据库,需要在本地添加一些配置
  16. layer.open弹出窗口后在子页面修改弹窗的title
  17. 我的第二本译作《精通OpenStack》上架啦:前言、目录和样章
  18. 数据加密之DES加密
  19. opencv7-ml之KNN
  20. Android性能测试工具之APT

热门文章

  1. 消息队列ActiveMQ的使用详解
  2. vscode中go插件配置
  3. ubuntu14.04安装使用NviDIA显卡驱动
  4. 【BubbleCup X】F:Product transformation
  5. hdu 2852 KiKi&#39;s K-Number (线段树)
  6. The algorithm of entropy realization
  7. 修改weblogic访问路径应用名称
  8. 用C++写程序的一些感悟
  9. 【会装】kylin的安装(填坑)和简单使用
  10. Ubuntu 各版本的几个国内更新源