题目链接

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

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int l[maxn], r[maxn], ans[maxn], a[maxn], q[maxn];
int main()
{
int n;
cin>>n;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
int i = , st = ;
while(i<=n) {
while(st&&a[q[st-]]>a[i]) {
r[q[st-]] = i-;
st--;
}
q[st++] = i;
i++;
}
while(st) {
r[q[st-]] = n;
st--;
}
i = n;
while(i>=) {
while(st&&a[q[st-]]>a[i]) {
l[q[st-]] = i+;
st--;
}
q[st++] = i;
i--;
}
while(st) {
l[q[st-]] = ;
st--;
}
memset(ans, , sizeof(ans));
for(int i = ; i<=n; i++) {
int len = r[i]-l[i]+;
if(ans[len]<a[i]) {
ans[len] = a[i];
}
}
for(i = n; i>=; i--) {
if(ans[i]>=ans[i-])
ans[i-] = ans[i];
}
for(int i = ; i<=n; i++) {
printf("%d ", ans[i]);
}
}

codeforces 547B. Mike and Feet 单调栈的更多相关文章

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

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

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

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

  4. Codeforces548D:Mike and Feet(单调栈)

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  5. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

  6. Codeforces 601B(贪心+斜率+组合数学+单调栈)

    题面 传送门 题目大意: L(h)的值是区间[L,R]内,abs(h[i]-h[j])/(i-j)的最大值.现在有q个询问,每个询问表示询问区间[L,R]内,所有子序列的L(h)的值的和 分析 将|h ...

  7. cf 547B. Mike and Feet dp

    题意: n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1 对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度 求:for ea ...

  8. Mike and Feet CodeForces - 548D (单调栈)

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  9. Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)

    题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...

随机推荐

  1. SSRS(rdl报表)分页显示表头和冻结表头

    <TablixRowHierarchy>          <TablixMembers>            <TablixMember>            ...

  2. Oracle中针对中文进行排序[Z]

    在oracle 9i之前,对中文的排序,是默认按2进制编码来进行排序的. 9i时增加了几种新的选择: 按中文拼音进行排序:SCHINESE_PINYIN_M 按中文部首进行排序:SCHINESE_RA ...

  3. Properties文件的XML格式(转)

    想必大家都用过*.properties文件,作为配置文件.但是,如果该文件写入了中文,待编译后内容就会成为乱码,使用native命令也好.使用ant执行编码转换也好,多少有点麻烦,与其如此,我们不如直 ...

  4. trie tree(字典树)

    hihocoder题目(http://hihocoder.com/problemset):#1014 trie树 #include <iostream> using namespace s ...

  5. leetcode remove Nth Node from End python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  6. MySQL之外键约束

    MySQL之外键约束 MySQL有两种常用的引擎类型:MyISAM和InnoDB.目前只有InnoDB引擎类型支持外键约束.InnoDB中外键约束定义的语法如下: [CONSTRAINT [symbo ...

  7. Vim配置 终端背景色配置

    在终端下使用vim进行编辑时,默认情况下,编辑的界面上是没有显示行号.语法高亮度显示.智能缩进 等功能的.为了更好的在vim下进行工作,需要手动设置一个配置文件:.vimrc.在启动vim时,当前用户 ...

  8. Ajax中send方法的使用

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

  9. Oracle系列:记录Record

    Oracle系列:记录Record   分类: [Oracle] (15) 版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle系列:记录(Record) 一,什么是记录(Record) ...

  10. iOS中Blocks的介绍

    1. 什么是Blocks Blocks是C语言的扩充功能.如果用一句话来概括就是:带有自动变量的匿名函数. 第一次看见Blocks的时候,感觉很类似C语言的函数指针,尤其是Block类型变量,更是有极 ...