Mike and Feet(CF 547B)
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 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.
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
#include<stdio.h>
const int N = 200005;
struct NODE
{
int h,w;
}S[N];
int h[N],ans[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d",&h[i]),ans[i]=0;
h[n++]=0;ans[n]=0;
int sum,top=0;
for(int i=0; i<n; i++){
sum=0;
while(top>0 && S[top].h>=h[i]){
sum+=S[top].w;
if(ans[sum]<S[top].h)
ans[sum]=S[top].h;
--top;
}
S[++top].h=h[i]; S[top].w=sum+1;
}
n--; /*
长度为i 的连续数中ans[i]是这i个数的最小数,但却是全部长度为i 的连续数中
最小中的最大数。长度i能够依据长度i+1更新大小。原因是ans[i+1]比在此区间内
的数都要小于等于,所以去掉边上的一个数答案不影响。 对于假设要求区间内的
最大值 ,仅仅需对以下的循环倒过来且比較符取反就可以。同理。 */
for(int i=n-1; i>=1; i--)
if(ans[i]<ans[i+1])
ans[i]=ans[i+1]; for(int i=1; i<n; i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n]);
}
Mike and Feet(CF 547B)的更多相关文章
- Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)
题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...
- D. Mike and Feet---cf548D(最值)
题目链接:http://codeforces.com/problemset/problem/548/D 给你n个数,对于(1,n)长度,让你找到线段的最小值的最大值是多少 #include<io ...
- B. Mike and Fun---cf548B(暴力求解)
题目链接:http://codeforces.com/problemset/problem/548/B 有一个n*m的矩阵,里面只有0和1,现在有Q个改变,每次都把(x,y)这点变为相反的点(0变1, ...
- 2019.4.24 一题(CF 809E)——推式子+虚树
题目:http://codeforces.com/contest/809/problem/E
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- (求凹包) Bicycle Race (CF 659D) 简单题
http://codeforces.com/contest/659/problem/D Maria participates in a bicycle race. The speedway t ...
- 线段树题集 (cf版)
lazy区间修改 : http://acm.hdu.edu.cn/showproblem.php?pid=4902 (hdu4902) http://acm.hdu.edu.cn/showpr ...
随机推荐
- NSIS:禁止选择安装路径和编辑安装目录
原文 NSIS:禁止选择安装路径和编辑安装目录 如果你想在安装包中禁止用户选择安装路径和编辑安装目录,有两种方式. 第一种:注释或删除安装目录选择页面 1 ;!insertmacro MUI_PA ...
- 解决Activity启动黑屏和设置android:windowIsTranslucent不兼容activity切换动画的问题
在该项目中遇到开Activity之后,黑屏问题,解决的办法是在网上通过设置发现theme和style特性,可以实现. http://www.cnblogs.com/sunzn/p/3407078.ht ...
- crm使用soap插入下拉框选项
//C# 代码: //InsertOptionValueRequest request = new InsertOptionValueRequest(); //request.OptionSetNam ...
- php形式的内容被处理
/** * 过滤HTML内容RETURN * * @param $string * @param bool $html * * @return array|string */ public stati ...
- Word2vec 讨论
我没有在自然语言处理完成.但基于Deep Learning 关注,自然知道一些Word2vec强大. Word2vec 是google 在2013年提供的一款将词表征为实数值向量的高效工具.而Word ...
- WSHPSRS-匹克选择列表生成器-SRS(R12.2.3)
匹克选择列表生成器-SRS(R12.2.3) --US Program:Pick Selection List Generation - SRS Short Name:WSHPSRS Appli ...
- jQuery简要dom操作
文本 dom 获取标签 $(选择). 创建一个标签对象 $("标签"): 由于所有的返回jQuery对象,能够调用链(无论jQuery API 回报jQuery对象) 插入标签 内 ...
- wikioi 1002 旁路
意甲冠军:这个问题刚开始的问题,有错误的含义,原桥始建于一条直线.无论多么遥远. 思维:dfs寻求答案的第一个问题.然后做最小生成树,双方不能大桥将设置INF即可了.然后假设用到INF的边就加上0即可 ...
- unix cd使用命令
[语法]: cd [夹] [说明]:此命令用于工作文件以改变当前的文件夹,使用环境变量没有参数$HOME 作为它的参数,$HOME 路径通常在注册时输入. [抽样]: cd 文件夹 c ...
- (一)AngularJS获取贴纸Hello World
一旦项目使用JQuery原创javascript,最近参加了一个项目,需要使用AngularJS.RequireJS比较框架,如汰渍. 这里写一些博客,记录自己的学习过程,虽然冠以原来的名字,资料,加 ...