题意:

n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1

对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度

求:for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.

对于每一个矩阵,我们先求出这个矩阵的l,r

l表示这个矩阵左边最靠近它的小于它的矩阵的下标

r表示这个矩阵右边最靠近它的小于它的矩阵的下标

即在区间(l,r)内,strength 等于这个矩阵的高度

注意:不包括l,r这2个矩阵

求l,r的值可以用dp

求完l,r后只需要把这些矩阵按照高度小到大sort一遍,

然后遍历一遍,不断更新ans数组即可

#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; const int MAXN = +; int ans[MAXN];
struct Node
{
int hei,l,r;
};
Node node[MAXN]; bool cmp(Node x,Node y)
{
return x.hei < y.hei;
} void solve()
{
int n;
scanf("%d",&n);
n++;
for(int i=;i<n;i++){
scanf("%d",&node[i].hei);
} node[].hei = ;
node[n].hei = ; for(int i=;i<n;i++){
node[i].l = i - ;
while(i > && node[node[i].l].hei >= node[i].hei){
node[i].l = node[node[i].l].l;
}
}
for(int i=n-;i>;i--){
node[i].r = i + ;
while(i < n && node[node[i].r].hei >= node[i].hei){
node[i].r = node[node[i].r].r;
}
} memset(ans,-,sizeof ans); sort(node+,node+n,cmp); for(int i=;i<n;i++){
int pos = node[i].r - node[i].l - ;
ans[pos] = max(ans[pos],node[i].hei);
} for(int i=n-;i>;i--){
ans[i] = max(ans[i],ans[i+]);
} for(int i=;i<n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]); return ;
} int main()
{
solve();
return ;
}

cf 547B. Mike and Feet dp的更多相关文章

  1. codeforces 547B. Mike and Feet 单调栈

    题目链接 用单调栈计算出一个数字, 左边第一个比他小的数字的位置, 右边比第一个他小的数字的位置, 然后len = r[i] - l[i] +1. ans[len] = max(ans[len], a ...

  2. Codeforces 547B. Mike and Feet[单调栈/队列]

    这道题用单调递增的单调栈维护每个数能够覆盖的最大区间即可. 对于   1 2 3 4 5 4 3 2 1 6 这组样例, 1能够覆盖的最大区间是10,2能够覆盖的最大区间是7,以此类推,我们可以使用单 ...

  3. Mike and Feet(CF 547B)

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

  4. CF #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. CF Mike and Feet (求连续区间内长度为i的最小值)单调栈

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

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

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

  8. CF 983B XOR-pyramid(区间dp,异或)

    CF 983B XOR-pyramid(区间dp,异或) 若有一个长度为m的数组b,定义函数f为: \(f(b) = \begin{cases} b[1] & \quad \text{if } ...

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

随机推荐

  1. POJ 1523 SPF(寻找关节点)

                                                                         SPF Time Limit: 1000MS   Memory ...

  2. UVALive-4670 Dominating Patterns(AC自动机)

    题目大意:找出出现次数最多的模式串. 题目分析:AC自动机裸题. 代码如下: # include<iostream> # include<cstdio> # include&l ...

  3. Oracle数据库五种约束

    oracle 数据库 数据表的5个约束类型:1.主键约束2.外键约束3.唯一约束4.检查约束5.非空约束 主键约束:用来唯一标示表中的一个列,一个表中的主键约束只能有一个,但是可以在一个主键约束中包含 ...

  4. meta name="viewport" 属性详解

    随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择.然而,每一款手机有不同的分辨率,不同屏幕 ...

  5. java中将汉字转换成16进制

    技术交流群:233513714 /** * 将汉字转换车16进制字符串 * @param str * @return st */ public static String enUnicode(Stri ...

  6. eclipse cdt代码悬停窗口背景颜色设置(转载)

    在eclipse中编写C++代码时,有一个很方便的功能,是当鼠标停放在某一个函数或变量上不同时,会出现一个悬停框,显示该函数或变量的声明 体.但是, 从Ubuntu 10.04之后,这个悬停框便出现了 ...

  7. pyzmq missing when running ipython notebook

    Q: I can run iPython, but when I try to initiate a notebook I get the following error: ~ ipython not ...

  8. ABBYY FineReader的图像编辑器功能使用方法

    日常工作中,有时可能需要对图像进行编辑,可是正常情况下大家都知道图像是不能直接编辑的,需要借助工具.ABBYY FineReader 12 OCR文字识别软件可以实现图像的手动编辑,接下来就具体给大家 ...

  9. uploadify多次加载导致页面无法加载

    function upld() { $('#file_upload').uploadify({ 'formData' : {'seccode':'<?php echo get_cookie('a ...

  10. 原生js的String类扩展

    文章转自:http://www.cnblogs.com/zfc2201/archive/2012/12/16/2820335.html JS String类拓展方法: //获取字符数组 String. ...