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. 【.NET 与树莓派】使用 GPIO 库

    上回老周在说准备工作的时候,提到过树莓派用金属盒散热的事情.有朋友会说,加了金属盒子接线不方便,就算用了"T"形板,毕竟是把导线延长了的.其实扩展板就是把原有的引脚引出(类似于延长 ...

  2. 终于可以愉快的撸Java异步代码了!

      异步响应式编程可以极大的提高系统的并发呑吐量,但由于Java没有类似于其他语言的Async/Await机制,所以只能通过CompletableFuture.thenXXX()来串联各个异步任务,这 ...

  3. 简单解析一下 Mybatis 常用的几个配置

    目录 核心配置文件 环境配置(environments) 属性(properties) 类型别名(typeAliases) 映射器(mappers) Mybatis 参考:https://mybati ...

  4. 【Linux】ntp的一些坑。你肯定遇到过

    ntpdate提示 19 Jan 10:33:11 ntpdate[29616]: no server suitable for synchronization found 这种问题从下面几个点开始验 ...

  5. linux命名小技巧(持续更新)

    一   向某个文件批量加入内容 1.1 向/etc/wxm文件添加一大段内容可以使用这个命令 [root@registry easyrsa3]# cat <<EOF >varsset ...

  6. 环境变量IFS

    环境变量IFS的值是由1个空格.1个制表符.1个换行符依序构成的字符串,也就是" \t\n"字符串. #查看IFS变量值的长度: test ~ # expr length &quo ...

  7. 【葵花宝典】一天掌握Kubernetes

    1.kubernetes介绍 kubernetes,简称K8s,是用8代替8个字符"ubernete"而成的缩写.是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kuber ...

  8. Sentry(v20.12.1) K8S 云原生架构探索,JavaScript 性能监控之管理 Transactions

    系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...

  9. [系列] Go - 基于 GORM 获取当前请求所执行的 SQL 信息

    前言 为了便于精准排查问题,需要将当前的请求信息与当前执行的 SQL 信息设置对应关系记录下来,记录的 SQL 信息包括: 执行 SQL 的当前时间: 执行 SQL 的文件地址和行号: 执行 SQL ...

  10. Development desciptor

    概述与作用: 部署描述符是用于描述Web应用程序的元数据,并为Java EE Web应用程序服务器部署和运行Web应用程序提供指令.从传统上来说,所有元数据都来自于部署描述符文件/WEB-INF/we ...