题意:

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. Python 基础语法(四)

    Python 基础语法(四) --------------------------------------------接 Python 基础语法(三)------------------------- ...

  2. ES

    https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-service-win.html https://www.e ...

  3. 使用 NGUI 实现头顶文字及血条

    以下是 NGUI HUD Text 实现的: 基本原理: 1. 在角色头顶绑一个点 Pivot,用于对齐 2. 因为界面总是覆盖在人物头顶信息的上面,所以将 UIRoot 分为2个 Panel:1) ...

  4. javascript error

    IE 6下expected identifier,string or number(缺少标示符.字符串或数字)其实就是多了一个逗号,之前没发现

  5. 委托,C#本身的委托(Action Func)

    1.Action 分为带泛型的和不带泛型的,带泛型可传入任何类型的参数. 格式如下: using System; using System.Collections.Generic; using Sys ...

  6. 怎么让OCR文字识别软件转换别的语言文档

    ABBYY PDF Transformer+让您可创建或转换希伯来语.意第绪语.日语.中文.泰语.韩语和阿拉伯语的文档.那么如何顺利使用这些复杂语言文字呢?小编教你两步骤轻松快速处理包含以下复杂语言文 ...

  7. OpenJudge计算概论-二维数组右上左下遍历

    /*====================================================================== 二维数组右上左下遍历 总时间限制: 1000ms 内存 ...

  8. 认识js函数对象(Function Object)

    认识函数对象(Function Object) 可以用function关键字定义一个函数,对于每个函数可以为其指定一个函数名,通过函 数名来进行调用.这些都是代码给用户的印象,而在JavaScript ...

  9. javascript中单体模式的实现

    单体模式作为一种软件开发模式在众多面向对象语言中得到了广泛的使用,在javascript中,单体模式也是使用非常广泛的,但是由于javascript语言拥有其独特的面向对象方式,导致其和一些传统面向对 ...

  10. ASP.NET MV3 部署网站 报"Could not load file or assembly ' System.Web.Helpers “ 错的解决方法

    转自:http://www.cnblogs.com/taven/archive/2011/08/14/2138077.html 国内很多网站空间都只支持.NET 2.0 和 .NET 3.0 3.5, ...