D. Mike and Feet
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
10
1 2 3 4 5 4 3 2 1 6
output
6 4 4 3 3 2 2 1 1 1 
学些数据结构才可以拯救自己吧,数据结构是省时的好东西哦,本来n^2可以变为nlgn甚至n,简直爆炸,单调栈就算能把复杂程度降到n的,太强辣,强行学习一波
其实我只是为了做出我们平台那道题,大佬讲让我用单调栈类似物,但是我并不了解这种数据结构啊,先mark下
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
struct node
{
int L, num;
}S;
stack <node> sta;
int a[N], ans[N];
int main ()
{
int n;
while (scanf ("%d", &n) != EOF)
{
for (int i=; i<n; i++)
scanf ("%d", &a[i]); for (int i=; i<=n; i++)
{
int l = ; while (!sta.empty ())
{
S = sta.top (); if (S.num < a[i]) break; int lr = S.L + l;
ans[lr] = max (ans[lr], S.num); l += S.L;
sta.pop ();
}
sta.push((node){l+, a[i]});
} for (int i=n; i>=; i--)
ans[i] = max (ans[i], ans[i+]);
for (int i=; i<n; i++)
printf ("%d ", ans[i]);
printf ("%d\n", ans[n]);
}
return ;
}

Codeforces Round #305 (Div. 2) D. 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(单调栈)

    题意 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. 盒子模型--IE与标准

    从上图可以看到标准 W3C 盒子模型的范围包括 margin.border.padding.content,并且 content 部分不包含其他部分. 从上图可以看到 IE 盒子模型的范围也包括 ma ...

  2. CString的GetBuffer和ReleaseBuffer

    GetBuffer()主要作用是将字符串的缓冲区长度锁定,releaseBuffer则是解除锁定,使得CString对象在以后的代码中继续可以实现长度自适应增长的功能. CString ::GetBu ...

  3. IOS自动化测试之UIAutomation

    通过Xcode工具编写运行测试脚本 1.当你有了一个应用的源代码之后,在Xcode工具中,首先选中被测应用,然后点击菜单栏中的“Product-Profile”,则会弹出Instruments工具,在 ...

  4. PHP 哈希表碰撞攻击

    理想情况下哈希表插入和查找操作的时间复杂度均为O(1),任何一个数据项可以在一个与哈希表长度无关的时间内计算出一个哈希值(key),然后在常量时间内定位到一个桶(术语bucket,表示哈希表中的一个位 ...

  5. 在ABAP里模拟实现Java Spring的依赖注入

    Dependency Injection- 依赖注入,在Java Spring框架中有着广泛地应用.通过依赖注入,我们不必在应用代码里繁琐地初始化依赖的资源,非常方便. 那么ABAP能否从语言层面上也 ...

  6. Git强制pull

    git fetch --all git reset --hard origin/master

  7. nuxt 初接触

    对于nuxt服务端渲染让人动心的是不会再想vue一样去定义无数的路由了这一点是挺爽的!!! 先直接晒张图 在api这块增加了一个fetch方法   它会在组件每次加载前被调用(即在服务端或切换至目标路 ...

  8. CAD控件的超链接事件(网页版)

    _DMxDrawXEvents::HyperlinkClick 有超连接的实体被点击了. 参数 说明 IDispatch* pEntity IMxDrawEntity,被点击的实体 DOUBLE dX ...

  9. netstat Recv-Q和Send-Q详解

    http://blog.csdn.net/sjin_1314/article/details/9853163 通过netstat -anp可以查看机器的当前连接状态:   Active Interne ...

  10. Spring 概念及特点 Spring下载地址 控制反转IoC实现原理

    Spring下载地址 http://repo.springsource.org/libs-release-local/org/springframework/spring/ Spring是开源full ...