题意

n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值

对于x(1<=x<=n) 求出最大的strength值

http://codeforces.com/contest/548/problem/D

思路

我们把每个数作为最小值能最远向左和右用单调栈处理出来,那么可以发现对于x长度的所有group,某个数延伸的区间长度如果大于等于x,则这个数对答案有贡献。

对于样例,我们处理出来后可以观察发现确有此规律:

然后就可以搞啦~

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define inf 0x3f3f3f3f
  4. #define ll long long
  5. const int N=200005;
  6. const int mod=1e9+7;
  7. const double eps=1e-8;
  8. const double PI = acos(-1.0);
  9. #define lowbit(x) (x&(-x))
  10. int g[N],L[N],R[N],a[N],h[N],mx[N];
  11. int main()
  12. {
  13. std::ios::sync_with_stdio(false);
  14. int n;
  15. scanf("%d",&n);
  16. for(int i=1; i<=n; i++)
  17. scanf("%d",&a[i]);
  18. a[n+1]=-1;
  19. stack<int> st;
  20. for(int i=1; i<=n; i++)
  21. {
  22. while(!st.empty()&&a[i]<=a[st.top()])
  23. {
  24. st.pop();
  25. }
  26. if(st.empty())
  27. {
  28. L[i]=1;
  29. }
  30. else
  31. {
  32. L[i]=st.top()+1;
  33. }
  34. st.push(i);
  35. }
  36. while(!st.empty()) st.pop();
  37. for(int i=n; i>=1; i--)
  38. {
  39. while(!st.empty()&&a[i]<=a[st.top()])
  40. st.pop();
  41. if(st.empty())
  42. {
  43. R[i]=n;
  44. }
  45. else
  46. R[i]=st.top()-1;
  47. st.push(i);
  48. }
  49. /* for(int i=1; i<=n; i++)
  50. {
  51. cout<<L[i]<<" "<<R[i]<<" "<<endl;
  52. }
  53. cout<<endl;*/
  54. for(int i=1; i<=n; i++)
  55. h[R[i]-L[i]+1]=max(h[R[i]-L[i]+1],a[i]);
  56. for(int i=n;i>=1;i--)
  57. mx[i]=max(mx[i+1],h[i]);
  58. for(int i=1;i<=n;i++)
  59. {
  60. printf("%d ",mx[i]);
  61. }
  62. puts("");
  63. return 0;
  64. }

Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)的更多相关文章

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

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

  3. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

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

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

  6. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  7. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  8. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

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

随机推荐

  1. remote: http basic: access denied fatal: authentication failed for '‘解决办法

    问题描述 由于这个项目代码使用https 进行clone,为什么?因为代码库ssh有问题!fuck! 导致在push代码的时候出现了 remote: http basic: access denied ...

  2. FLOPS

    FLOPS FLOPS(Float Operations Per Second):每秒浮点运算量,是衡量吞吐率的一个单位,通过折算到具体的浮点操作数量上. 所谓,吞吐率——就如同水管,每秒可以流出多少 ...

  3. echarts使用------地图生成----省市地图的生成及其他相关细节调整

    为使用多种业务场景,百度echarts地图示例只有中国地图,那么在使用省市地图的时候,就需要我们使用省市的地图数据了 以下为陕西西安市的地图示例: 此页面引用echarts的js:http://ech ...

  4. Leetcode173. 二叉搜索树迭代器

    空间复杂度O(h)而不是O(n),因此不能直接在初始化函数中做中序遍历将结果存储到数组中.next()和hasNext()时间复杂度为O(1)首先本题很容易想到用二叉树的中序遍历去解决,外加注意点1. ...

  5. vue 多种方式控制style属性

    一共用到了两种方式: 第一种:对象 第二种:数组 看代码: <!doctype html> <html lang="en"> <head> &l ...

  6. 国内Java面试总是问StringBuffer,StringBuilder区别是啥?档次为什么这么低?

    GitHub 6.6k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 6.6k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 6.6k Star 的 ...

  7. 解惑:在Ubuntu18.04.2的idea上运行Scala支持的spark程序遇到的问题

    解惑:在Ubuntu18.04.2的idea上运行Scala支持的spark程序遇到的问题 一.前言 最近在做一点小的实验,用到了Scala,spark这些东西,于是在Linux平台上来完成,结果一个 ...

  8. java优化细节记录

    此处是为了记录一些优化细节,从网上收集而来,仅供后续代码开发参考使用,如发现更好的,会不断完善 首先确认代码优化的目标是: 减小代码的体积 提高代码运行的效率 代码优化细节 1.尽量指定类.方法的fi ...

  9. N!(hdu1042)

    N! Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process ...

  10. POJ 3041 Asteroids(二分图最大匹配)

    ###题目链接### 题目大意: 给你 N 和 K ,在一个 N * N 个图上有 K 个 小行星.有一个可以横着切或竖着切的武器,问最少切多少次,所有行星都会被毁灭. 分析: 将 1~n 行数加入左 ...