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. 杂谈 什么是伪共享(false sharing)?

    问题 (1)什么是 CPU 缓存行? (2)什么是内存屏障? (3)什么是伪共享? (4)如何避免伪共享? CPU缓存架构 CPU 是计算机的心脏,所有运算和程序最终都要由它来执行. 主内存(RAM) ...

  2. 2017 五一 清北学堂 Day1模拟考试结题报告

    预计分数:100+50+50 实际分数:5+50+100 =.= 多重背包 (backpack.cpp/c/pas) (1s/256M) 题目描述 提供一个背包,它最多能负载重量为W的物品. 现在给出 ...

  3. Linux下环境搭建(一)——java、tomcat配置

    通过2个周末小憩的时间,终究是把linux环境下的jenkins+gitlab+jmeter框架给弄好了.jenkins的配置系列文章,可以翻看我以前的博文.此次,就将在linux下搭建环境的过程以博 ...

  4. 最小化安装centos后ifconfig看不到eth0

    最小换安装centos后,ifconfig看不到eth0,只看到一个lo ifup eth0

  5. SM2-DE

    SM2单证书认证 下端 导入根证书以及通用证书[具有签名和加密证书的功能]和远端的证书[获取远端公钥信息] 1.配置证书域 crypto ca identity gernal exit 2.通过复制粘 ...

  6. 洛谷 P1774 最接近神的人_NOI导刊2010提高(02)

    题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古代人进行某种活动的图案.而石门上方用古代文写着“神的殿堂”.小FF猜想里面应该就有王室的 ...

  7. (十二)maven之nexus仓库的基本用法

    nexus仓库的基本用法 ① 启动nexus. 上一章有提到:https://www.cnblogs.com/NYfor2018/p/9079068.html ② 访问http://localhost ...

  8. 获取显示设备的名称及PNPDeviceID

    实现效果: 知识运用: ManagementObjectSearcher类和ManagementObject类 实现代码: private void button1_Click(object send ...

  9. CPP-基础:单目运算符重载

    关于++运算符前置和后置重载的实现实例: #include <iostream> using namespace std; //创建时钟类 class Clock { public: Cl ...

  10. sstable, bigtable,leveldb,cassandra,hbase的lsm基础

    先看懂文献1和2 1. 先了解sstable.SSTable: Sorted String Table [2] [10] WiscKey:  类似myisam, key value分离, 根据ssd优 ...