Codeforces Round #305 (Div. 2) D. Mike and Feet
1 second
256 megabytes
standard input
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.
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.
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
10
1 2 3 4 5 4 3 2 1 6
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的更多相关文章
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 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 ...
- 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 ...
- Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
- 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 ...
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- 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 ...
随机推荐
- 【转】微信小程序原理
微信小程序原理 kamidox 关注 2016.11.05 09:42* 字数 2356 阅读 14621评论 5喜欢 75赞赏 1 微信小程序使用了前端技术栈 JavaScript/WXML/WXS ...
- vue2.0:(二)、mock数据
什么是mock数据呢?很多情况下,后台的搭建比起前端来说要麻烦的多,所以,常常是前端写好了页面以后后台接口却没有写好,但是在一个项目中,接口调试确实是最浪费时间的,所以,往往前端需要自己模拟数据. 第 ...
- main函数与命令行参数
main函数的概念 C语言中main函数称之为主函数 一个c程序从main函数开始执行的 下面的main函数定义正确吗? main函数的本质 main函数是操作系统调用的函数 操作系统总是将main函 ...
- uvm_monitor——借我一双慧眼
monitor 用来捕获(监视)和检查总线的信号是否满足预期的要求.所有的user_monitor 继承自uvm_monitor,uvm_monitor继承自uvm_component,从源代码来看里 ...
- 解决常见SVN冲突问题(转)
转自:http://www.w3cfuns.com/blog-5443287-5403523.html 一个大项目在开发中可能会拆分成几个小项目,分别分去,同时共通的部分再由人做,做完后再统一合并.同 ...
- 导致实例逐出的五大问题 (文档 ID 1526186.1)
适用于: Oracle Database - Enterprise Edition - 版本 10.2.0.1 到 11.2.0.3 [发行版 10.2 到 11.2]本文档所含信息适用于所有平台 用 ...
- (五)VMware Harbor 部署之SSL
转自:https://www.cnblogs.com/Rcsec/p/8479728.html 1 .签名证书与自签名证书 签名证书:由权威颁发机构颁发给服务器或者个人用于证明自己身份的东西. 自签名 ...
- CAD交互绘制圆形批注(网页版)
js中实现代码说明: 动态拖放时的绘制事件: function DoDynWorldDrawFun(dX,dY,pWorldDraw,pData) { //自定义实体的GUID标识符 var sGui ...
- 利用python进行数据分析2_数据采集与操作
txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...
- Arch Linux 天坑
https://wiki.archlinux.org/index.php/Samba_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) samba gui客户端 smb4 ...