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 ...
随机推荐
- [SignalR]Groups操作——后续
原文:[SignalR]Groups操作——后续 继续http://www.cnblogs.com/YanZhiwei/p/3359175.html之前,那怎么实现发送的消息推送到隶属于这个组的用户呢 ...
- 用Unicode迎接未来
项目中使用了emoji,然后,问题产生了,后端MySQL数据库无法存储emoji字符,悲了个剧. emoji是Unicode字符集的子集,Unicode的使用应该非常普遍了,怎么会 ...
- SQL 将URL编码转汉字!
原文:SQL 将URL编码转汉字! -- ============================================= -- 作 者: ruijc -- 描 述: 将Url编码转明文字符 ...
- Android与服务器端数据交互(转)
上一节中我们通过http协议,采用HttpClient向服务器端action请求数据.当然调用服务器端方法获取数据并不止这一种.WebService也可以为我们提供所需数据,那么什么是webServi ...
- 创建线程的两种方式:继承Thread类和实现Runnable接口
第一种方式:继承Thread类 步骤:1.定义类继承Thread 2.覆写Threa类的run方法. 自定义代码放在run方法中,让线程运行 3.调用线程的star方法, 该线程有两个作用:启动线程, ...
- JS基础——数组总结
JS中数组被觉得是一种对象,慢慢的,怎么忽然感觉,JS中仅仅要能够独立出来的概念怎么都能够当成对象来解释呢?有点儿怀疑.继续学吧.先来总结一下JS中数组是怎样详细使用的. 一.创建 数组的创建在JS中 ...
- android 性能測试iozone篇
一:简单介绍 iozone是一个文件系统的benchmark工具, 用于測试不同的操作系统中文件系统的读写性能, 能够測试下面13种模式 0=write/rewrite 1=read/re-read ...
- SSIS从理论到实战,再到应用(3)----SSIS包的变量,约束,常用容器
原文:SSIS从理论到实战,再到应用(3)----SSIS包的变量,约束,常用容器 上期回顾: SSIS从理论到实战,再到应用(2)----SSIS包的控制流 首先我们来看看包里面的变量 SSIS ...
- Java数据结构与算法(13) - ch06递归(归并排序)
时间为O(N*logN). 归并排序的一个缺点是它需要在存储器中有另一个大小等于被排序的数据项数目的数组.归并两个有序的数组.利用递归,不断的将数组进行二分法排序,然后进行归并即可.
- 多线程相互排斥--mutex(二)
不知道大家对多线程或多进程间的同步相互排斥的控制机制了解的怎么样,事实上有非常多种方法能够实现这个目的,可是这些方法事实上由4种最主要的方法实现.这4种最主要的方法详细定义例如以下:在这有讲得不正确的 ...