题意:

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. Vue.js相关知识1

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. hihoCoder #1040 (判断是否为矩形)

    题目大意:给四条线段,问能否构成一个矩形? 题目分析:先判断能否构成四边形,然后选一条边,看另外三条边中是否为一条与他平行,两条垂直. 代码如下: # include<iostream> ...

  3. Python学习(2)——编码

    今天写了个程序但是在DOS窗口和IDEL窗口调试的结果不一样,有些郁闷~ #!/usr/bin/env python #coding=utf-8 #python version:2.7.3 #syst ...

  4. 关于MSP430中断机制

    中断很大程度上体现了一款单片机的性能,从这一点将MSP430在中断方面做得很不错,主要是提供了非常丰富的中断源,基本的有IO中断,定时器中断和一些接口中断(SPI,UART,I2C)等等.     现 ...

  5. Goal driven performance optimization

    When your goal is to optimize application performance it is very important to understand what goal d ...

  6. centos7下环境配置

    1:  安装memcached 问题:error: libevent is required. If it's already installed, specify its path using –w ...

  7. Oracle数据库查询语句

    编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据: 1.列出至少有一个员工的所有部门. SQL语句: select * from SCOTT.DEPT where dept ...

  8. wikioi 1076 排序 【这里含冒泡、选择、插入以及快排库函数的调用】

    /*=================================================================== 1076 排序 题目描述 Description 给出n和n ...

  9. webpack需要全局安装,才能使用webpack命令

    webpack全局安装,具体项目中才能使用webpack命令: npm install webpack -g

  10. javascript模块化编程(AMD规范的加载器)

    关于AMD规范可以参考阮一峰的这篇文章Javascript模块化编程(二):AMD规范 简单来说,AMD规范就是异步方式加载模块的一种方式,避免因为模块加载过慢而导致浏览器“假死”. 先贴一个学习地址 ...