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 strengthof
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 test(s)
input
10
1 2 3 4 5 4 3 2 1 6
output

6 4 4 3 3 2 2 1 1 1

这题可以用单调栈做,维护一个栈,记录minmum(该区间的最小值)和count(区间的总长度)。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define maxn 200060
int ans[maxn];
struct node{
int count,minmum;
}stack[maxn];
int main()
{
int n,m,i,j,top,count,b;
while(scanf("%d",&n)!=EOF)
{
memset(ans,0,sizeof(ans));
top=0;
for(i=1;i<=n;i++){
scanf("%d",&b);
count=0;
while(top>0 && stack[top].minmum>=b){
stack[top].count+=count;
count=stack[top].count;
if(ans[count]<stack[top].minmum){
ans[count]=stack[top].minmum;
}
top--;
}
top++;
stack[top].minmum=b;
stack[top].count=count+1;
}
count=0;
while(top>0){
stack[top].count+=count;
count=stack[top].count;
if(ans[count]<stack[top].minmum){
ans[count]=stack[top].minmum;
}
top--;
}
for(i=n;i>=2;i--){
if(ans[i]>ans[i-1]){/*这里算出来的ans[i]是连续长度为i的区间的最小值,但这个最小值是所有连续长度为i的区间长度的最大值,下面如果ans[i+1]比ans[i]大,那么ans[i]可以更新为ans[i+1],因为如果i+1个连续数区间的最小值的最大值是b,那么去掉一个数,一定可以做到长度为i的连续数区间的最大值是b。*/
ans[i-1]=ans[i];
}
}
for(i=1;i<=n-1;i++){
printf("%d ",ans[i]);
}
printf("%d\n",ans[i]);
}
return 0;
}


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

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

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

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

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

  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

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

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

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

  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. Received empty response from Zabbix Agent at [agent]. Assuming that agent dropped connection because of access permission

    Received empty response from Zabbix Agent at [agent]. Assuming that agent dropped connection because ...

  2. 电子邮箱、邮件地址、网站地址正则表达式!几个有用的RE、regex、regexp!

    几个常用的正则表达式! r"\w[-\w\.]*@\w[-\w]*(\.\w[-\w]*)+" 这个是电子邮件地址的. r"<TAG\b[^>]*<(. ...

  3. oracle创建恢复编录(recovery catalog)

    1.在要作为恢复编录的数据库创建用户 create user rman identified by oracle default tablespace system temporary TABLESP ...

  4. toad for oracle自定义快捷sql

    View--->Toad Options--->Behavior--->Auto replace--->

  5. 入门OJ:郭嘉的消息传递

    题目描述 我们的郭嘉大大在曹操这过得逍遥自在,但是有一天曹操给了他一个任务,在建邺城内有N(<=1000)个袁绍的奸细 将他们从1到N进行编号,同时他们之间存在一种传递关系,即若C[i,j]=1 ...

  6. 低功耗降线性稳压器,24V转5V降压芯片

    PW2330开发了一种高效率的同步降压DC-DC变换器3A输出电流.PW2330在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导 损失.PW2330 ...

  7. Vue案例之todoLIst实现

    使用Vue实现todolist案例,如有不对敬请大佬多多指教 功能: 1.增加功能:在新增版块里面的输入框内输入数据,点击后面的"添加"按钮,将输入的数据添加到列表中,默认是未完成 ...

  8. vue中computed/method/watch的区别

    摘要:本文通过官方文档结合源码来分析computed/method/watch的区别. Tips:本文分析的源码版本是v2.6.11,文章中牵涉到vue响应式系统原理部分,如果不是很了解,建议先阅读上 ...

  9. nfs samba文件共享服务

    (注意:实验之前强关闭selinux和防火墙) 一丶nfs ① 1.服务端 启动服务 systemctl start nfs.service   配置文件 vim /etc/exports share ...

  10. zabbix客户端监控脚本shell

    zabbix客户端监控脚本shell #!/bin/sh sleep 3 zabbixdir=`pwd` zabbix_version=4.2.5 ###指定版本,最好和server端吻合版本,可以自 ...