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

Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈的更多相关文章

  1. Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

  3. Codeforces Round #305 (Div. 2) D. Mike and Feet

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)

    题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...

  5. Codeforces Round #305 (Div. 1) B. Mike and Feet

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  6. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  7. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  8. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  9. Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力

     B. Mike and Fun Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...

随机推荐

  1. 多维数组的字符依次输出,用python实现

    #-*- coding=utf-8 -*-listm=["s","l","z","x","l",&q ...

  2. 64_o2

    openrdf-sesame-queryrender-2.8.10-2.fc26.noarch..> 11-Feb-2017 18:38 52014 openrdf-sesame-queryre ...

  3. 很多人都没用过的轻量级Oracle数据库数据导出工具SQLLDR2——性能超赞

    SQLLDR2 介绍 每周发表一篇数据库或大数据相关的帖子,敬请关注 1. 工具介绍 Sqluldr2(SQL * UnLoader 第二版)是灵活与强大的 Oracle 文本导出程序,已被大众使 用 ...

  4. ActiveMQ-Network of brokers集群模式

    概述 在ActiveMQ运行过程中,如果发生某个queue只有生产者没有消费者的情况时,消息就会产生积压.Network of brokers模式通过将积压的消息转发给处于同一network的其它br ...

  5. URL中斜杠/和反斜杠\的区别小结

    Unix使用斜杆/ 作为路径分隔符,而web应用最新使用在Unix系统上面,所以目前所有的网络地址都采用 斜杆/ 作为分隔符. Windows由于使用 斜杆/ 作为DOS命令提示符的参数标志了,为了不 ...

  6. HDU 1255 覆盖的面积(线段树:扫描线求面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题目大意:给你若干个矩形,让你求这些矩形重叠两次及以上的部分的面积. 解题思路:模板题,跟HDU ...

  7. 在eclipse中使用Maven3(笔记二)

    笔记本二   在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...

  8. FPGA 17最佳论文导读 ESE: Efficient Speech Recognition Engine with Compressed LSTM on FPGA

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.机器学习技术感兴趣的同学加入. 后面陆续写一些关于神经网络加 ...

  9. hive的窗口函数cume_dist、fercent_rank

    一.cume_dist 这两个序列分析函数不是很常用,这里也介绍一下.注意: 序列函数不支持WINDOW子句. 数据准备: d1,user1, d1,user2, d1,user3, d2,user4 ...

  10. 【转】【delphi】ClientDataSet详细解读

    原文:http://www.cnblogs.com/lcw/p/3496764.html TClientDataSet的基本属性和方法 TClientDataSet控件继承自TDataSet,其数据存 ...