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 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.

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.

Sample test(s)
input
  1. 10
  2. 1 2 3 4 5 4 3 2 1 6
output
  1. 6 4 4 3 3 2 2 1 1 1


题意:给n个数。问连续区间长度为1,2,3,4,....n 所相应的区间长度最小值中的最大值是多少。
解题:单调栈。


  1. #include<stdio.h>
  2. const int N = 200005;
  3. struct NODE
  4. {
  5. int h,w;
  6. }S[N];
  7. int h[N],ans[N];
  8. int main()
  9. {
  10. int n;
  11. scanf("%d",&n);
  12. for(int i=0; i<n; i++)
  13. scanf("%d",&h[i]),ans[i]=0;
  14. h[n++]=0;ans[n]=0;
  15. int sum,top=0;
  16. for(int i=0; i<n; i++){
  17. sum=0;
  18. while(top>0 && S[top].h>=h[i]){
  19. sum+=S[top].w;
  20. if(ans[sum]<S[top].h)
  21. ans[sum]=S[top].h;
  22. --top;
  23. }
  24. S[++top].h=h[i]; S[top].w=sum+1;
  25. }
  26. n--;
  27.  
  28. /*
  29. 长度为i 的连续数中ans[i]是这i个数的最小数,但却是全部长度为i 的连续数中
  30. 最小中的最大数。长度i能够依据长度i+1更新大小。原因是ans[i+1]比在此区间内
  31. 的数都要小于等于,所以去掉边上的一个数答案不影响。
  32.  
  33. 对于假设要求区间内的
  34. 最大值 ,仅仅需对以下的循环倒过来且比較符取反就可以。同理。
  35.  
  36. */
  37. for(int i=n-1; i>=1; i--)
  38. if(ans[i]<ans[i+1])
  39. ans[i]=ans[i+1];
  40.  
  41. for(int i=1; i<n; i++)
  42. printf("%d ",ans[i]);
  43. printf("%d\n",ans[n]);
  44. }




Mike and Feet(CF 547B)的更多相关文章

  1. Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)

    题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...

  2. CF Mike and Feet (求连续区间内长度为i的最小值)单调栈

    Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)

    题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...

  4. D. Mike and Feet---cf548D(最值)

    题目链接:http://codeforces.com/problemset/problem/548/D 给你n个数,对于(1,n)长度,让你找到线段的最小值的最大值是多少 #include<io ...

  5. B. Mike and Fun---cf548B(暴力求解)

    题目链接:http://codeforces.com/problemset/problem/548/B 有一个n*m的矩阵,里面只有0和1,现在有Q个改变,每次都把(x,y)这点变为相反的点(0变1, ...

  6. 2019.4.24 一题(CF 809E)——推式子+虚树

    题目:http://codeforces.com/contest/809/problem/E

  7. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  8. (求凹包) Bicycle Race (CF 659D) 简单题

    http://codeforces.com/contest/659/problem/D     Maria participates in a bicycle race. The speedway t ...

  9. 线段树题集 (cf版)

    lazy区间修改   : http://acm.hdu.edu.cn/showproblem.php?pid=4902   (hdu4902) http://acm.hdu.edu.cn/showpr ...

随机推荐

  1. Catalan数总结

    财产: 前20条目:1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, ...

  2. [转]从.NET转JAVA开发

    [转]从.NET转JAVA开发 .NET转JAVA其实也很简单,自己动手写几个DEMO差不多就了解了 1. JAVA做互联网开发多半只会用到开源框架Struts2 Hibernate 和Spring, ...

  3. Android开发人员官方站点文档 - 国内踏得网镜像

    Android Developer 安卓开发人员官方站点无法正常訪问.即使FQ因为网络原因依旧訪问缓慢. 故整理相关字体.脚本.样式.页面资源,在踏得网server上建立了本地镜像.初始镜像时间201 ...

  4. 【关节点+桥】关节点和桥模板 Tarjan

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; con ...

  5. Stopwatch计时器、秒表 C#

    .NET2.0也提供了这样一个秒表:Stopwatch类,它可以比较精确地测量时间. 速度测试: 软件的性能和可测性是一个复杂的主题.要确保应用程序能够满足用户的期望,就需要在开发周期内考虑它的性能和 ...

  6. bigdata_一篇文看懂Hadoop

    本文转载:暂未找到原出处,如需署名 请联系 我们很荣幸能够见证Hadoop十年从无到有,再到称王.感动于技术的日新月异时,希望通过这篇内容深入解读Hadoop的昨天.今天和明天,憧憬下一个十年. 本文 ...

  7. 微信公众平台企业号验证接口、回调 PHP版

    微信公众平台企业号验证接口.回调 PHP版,本人为了解决这个企业号的验证和发送消息的问题,整整研究了几天时间,由于微信企业号刚推出来,网上资料太少了!后来在一些朋友的帮助下和本人重复调试完好下,最终整 ...

  8. linux_shell_类似sql的orderby 取最大值

    {} {} {} {} {} {} {} {} {} {} 需求场景 ,通过shell 筛选 每分钟的最大一条输出(最后一条) : .info | head

  9. 【C++基础】类的组合

    所谓类的组合是指:类中的成员数据是还有一个类的对象或者是还有一个类的指针或引用.通过类的组合能够在已有的抽象的基础上实现更复杂的抽象. 比如: 1.按值组合 #include<iostream. ...

  10. &lt;七&gt;阅读&lt;&lt;大话设计模式&gt;&gt;该模板模型

    哈哈,没想到.在不知不觉中拥有第七书面文章,看来我仍然非常有毅力. 上坚持一件事非常easy,仅仅要你每天不断的朝着自己的目标出发,不论什么事情都不会挡着你.好了大道理不多说,谁都懂.那看看这个模板模 ...