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. 基于Python实现的系统SLA可用性统计

    基于Python实现的系统SLA可用性统计 1. 介绍 SLA是Service Level Agreement的英文缩写,也叫服务质量协议.根据SRE Google运维解密一书中的定义: SLA是服务 ...

  2. Docker学习笔记之搭建Docker私有仓库

    Docker仓库服务器名为Docker注册(registry)服务器.可以使用docker push命令将镜像上传到注册服务器,也可以使用docker pull命令下载服务器的镜像. Docker注册 ...

  3. Java 基于 mysql-connector-java 编写一个 JDBC 工具类

    用到的 jar 包 jar包地址: mysql-connector-java-5.1.47.jar junit-4.13.jar Maven: <!-- mysql驱动 --> <d ...

  4. HarmonyOS三方件开发指南(5)——Photoview组件

    PhotoView使用说明 1.  PhotoView功能介绍1.1 组件介绍:        PhotoView是一个继承自Image的组件,不同之处在于:它可以进行图击放大功能,手势缩放功能(暂无 ...

  5. 【老孟Flutter】源码分析系列之InheritedWidget

    老孟导读:这是2021年源码系列的第一篇文章,其实源码系列的文章不是特别受欢迎,一个原因是原理性的知识非常枯燥,我自己看源码的时候特别有感触,二是想把源码分析讲的通俗易懂非常困难,自己明白 和 让别人 ...

  6. ctfhub技能树—sql注入—Cookie注入

    手注 打开靶机 查看页面信息 查找cookie 测试是否为cookie注入 抓包 尝试注入 成功查询到数据库名 查询表名 查询字段名 查询字段信息 成功拿到flag sqlmap 查询数据库名 pyt ...

  7. python optparse模块的用法

    引用原博主文章链接: https://www.cnblogs.com/darkpig/p/5717902.html

  8. Netty学习:伪共享

    目录 Netty中的伪共享 伪共享的原理以及介绍 Netty中的伪共享 先说为什么知道这个概念吧,期初看Netty源码的时候,看到了NioEventLoop的构建,其中有这么一句代码: private ...

  9. 前端面试之HTML5的新变化

    前端面试之HTML5的新变化 H5新增语义化标签 头部标签 <header> :头部标签 <nav> :导航标签 <article> :内容标签 <secti ...

  10. oracle模糊查询mysql的区别

    https://blog.csdn.net/weixin_38673554/article/details/86503982#_1 oracle与使用mysql的区别 https://www.cnbl ...