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. LDA线性判别分析

    LDA线性判别分析 给定训练集,设法将样例投影到一条直线上,使得同类样例的投影点尽可能的近,异类样例点尽可能的远,对新样本进行分类的时候,将新样本同样的投影,再根据投影得到的位置进行判断,这个新样本的 ...

  2. C# 加密解密以及sha256不可逆加密案例

    class Program { static void Main(string[] args) { string aa = "身份证"; string bb = "key ...

  3. mac 上 sublime text2 快捷键

    打开/前往: ⌘T 前往文件 ⌘⌃P 前往项目⌘R 前往 method⌘⇧P 命令提示⌃G 前往行⌃ ` python 控制台 编辑:⌘L 选择行 (重复按下将下一行加入选择)⌘D 选择词 (重复按下 ...

  4. 苹果的浏览器safari无法识别 2016-1-1这样的日期,会返回Invalid Date

    1.很多时候我们遇到的日期是2016-1-1这样的,中间是带横线的,但是有时候我们需要转化为标准的时间,即使用new Date(time)这样的方法,这时在safari浏览器里面Invalid Dat ...

  5. Maven如何发布项目到一个Tomcat中

    首先,在本地tomcat的conf/tomcat-users.xml 中配置一个user,准备让maven接入时使用: <role rolename="admin-gui"/ ...

  6. c++输出保留固定小数位数

    cout<<setprecision(6)<<fixed<<ans<<endl;

  7. 3.rabbitmq 发布/订阅

    1. 发布者 #coding:utf8 import pika import json import sys message = ''.join(sys.argv[1:]) or "hell ...

  8. ISSCC 2017论文导读 Session 14 Deep Learning Processors,DNPU: An 8.1TOPS/W Reconfigurable CNN-RNN

    转载请注明,本文出自Bin的专栏http://blog.csdn.net/xbinworld,谢谢! DNPU: An 8.1TOPS/W Reconfigurable CNN-RNN Process ...

  9. 洛谷P1482 Cantor表(升级版) 题解

    题目传送门 此题zha一看非常简单. 再一看特别简单. 最后瞟一眼,还是很简单. 所以在此就唠一下GCD大法吧: int gcd(int x,int y){ if(x<y) return gcd ...

  10. CentOS7.5安装Mysql5.7.22

    一 下载 下载地址:https://www.mysql.com/downloads/ 1 点击第一个链接地址,进入MySQL官方网站,单击“Downloads”下载Tab页,进入下载界面 2 找到Co ...