题意:

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. PHP内存消耗

    由于变量占用的空间不一样,所以其消耗的内存大小也不一样,在PHP中我们可以通过使用“memory_get_usage”来获取当前PHP消耗的内存.但是根据操作系统.PHP版本以及PHP的运行方式可能输 ...

  2. fs event_socket

    mod_event_socket     Skip to end of metadata   Created by John Boteler, last modified by Niek Vlesse ...

  3. AIDL Service Android进程间通信机制

    转载出处:http://www.apkbus.com/home.php?mod=space&do=blog&uid=664680&id=59465 我们知道,在Android ...

  4. Java collection 的一些介绍 集合

    collections主要提供一些,排序的算法,随机的,反向的,  collection 是容器的祖先接口 线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应 ...

  5. selenium+python自动化之操作浏览器

    一.打开网站 1.第一步:从selenium里面导入webdriver模块 2.打开Firefox浏览器(Ie和Chrome对应下面的) 3.打开百度网址 二.设置休眠 1.由于打开百度网址后,页面加 ...

  6. php 同步因子的并发处理

    在php中,如果处理支付时,会涉及到并发. 具体体现在同步通知支付结果和异步通知结果. 拿支付宝来说,同步通知call_back和异步通知notify是没有固定先后顺序的. 有可能notify先通知到 ...

  7. 客户端TortoiseSVN的安装及使用方法

    一.客户端TortoiseSVN的安装 运行TortoiseSVN程序,点击Next,下面的截图顺序即为安装步骤: 图1: 图2: 图3: 图4: 点击Finish按钮后会提示重启系统,其实不重启也没 ...

  8. mysql中的null字段值的处理及大小写问题

    在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...

  9. 如何创建自己的docker image并上传到DockerHub上

    这里,记录一下比较常用的docker操作细节,对于初次使用者,可能有很大的帮助. docker作为云计算Paas层面的东西,风靡全世界了,主要是因为它小巧,好用,功能强大.今天主要介绍一下如何依据自己 ...

  10. 【linux】关机重启命令

    shutdown: [参数][时间] -h:关机 -r:重启 -c:取消上一次关机或重启 [root@paulinux ~]# shutdown -h now ##马上重启 [root@paulinu ...