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 ...
随机推荐
- DDD领域驱动设计仓储Repository
DDD领域驱动设计初探(二):仓储Repository(上) 前言:上篇介绍了DDD设计Demo里面的聚合划分以及实体和聚合根的设计,这章继续来说说DDD里面最具争议的话题之一的仓储Repositor ...
- List toArrays()
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ListToArray ...
- Round #169 (Div. 2)D. Little Girl and Maximum XOR
1.首先是要找到一个位置从左至右,作l这一个是0,r这一个是1. 2.实例01011,10100.你将能够找到01111和10000. #include<cstdio> #include& ...
- Android开源项目总结
Android开源项目--分类汇总 Android开源项目第一篇--个性化控件(View)篇 包含ListView.ActionBar.Menu.ViewPager.Gallery.GridView. ...
- Yeoman generators 创建 ASP.NET 应用程序
Yeoman generators 创建 ASP.NET 应用程序 上一篇:<Windows 搭建 .NET 跨平台环境并运行应用程序> 阅读目录: Install Node.js Ins ...
- BIEE在creating domain步骤停止的解决的方法
1.错误现象: biee11g creating domain csf entries will not be parsed since the adminserver is unreachable ...
- 基于STM32旋转编码器
..\..\SYSTEM\usart\usart.c(1): error: #5: cannot open source input file "sys.h": No such ...
- 深入了解setInterval方法
相信大家对setInterval方法肯定非常熟悉,但不少人对其缺乏深入的了解,致使当一个flash里有多个setInterval的时候就容易混淆,该清除的间隔lID没有清除,不该清除的时候却清除了.对 ...
- 你知道OneNote的OCR功能吗?office lens为其增大威力,中文也识别
原文:[原创]你知道OneNote的OCR功能吗?office lens为其增大威力,中文也识别 OneNote提供了强大的从图片中取出文字的功能,大家只要装上了桌面版OneNote(本人用的2013 ...
- 【百度地图API】今日小年大进步,齐头共进贺佳节——API优化升级上线,不再增加内存消耗
原文:[百度地图API]今日小年大进步,齐头共进贺佳节--API优化升级上线,不再增加内存消耗 任务描述: 今天是2011年01月26日,小年夜.百度地图API在小年夜献给广大API爱好者一份给力的礼 ...