http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1437

题意:

思路:

单调栈题。求出以每个数为区间最大值的区间范围即可。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = *1e5+; int n;
int a[maxn];
int sta[maxn];
int l[maxn], r[maxn];
int ans[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int top = ;
for(int i=;i<=n;i++)
{
while(top && a[sta[top]]>=a[i]) top--;
if(top==) l[i]=;
else l[i]=sta[top]+;
sta[++top]=i;
}
top = ;
for(int i=n;i>=;i--)
{
while(top && a[sta[top]]>a[i]) top--;
if(top==) r[i]=n;
else r[i]=sta[top]-;
sta[++top]=i;
}
for(int i=;i<=n;i++)
ans[r[i]-l[i]+]=max(ans[r[i]-l[i]+],a[i]);
for(int i=n-;i>=;i--)
ans[i]=max(ans[i],ans[i+]);
for(int i=;i<=n;i++)
printf("%d%c",ans[i],i==n?'\n':' ');
}
return ;
}

51nod 1437 迈克步(单调栈)的更多相关文章

  1. 51nod 1437 迈克步 单调栈

    利用单调栈高效的求出,一个数a[i]在哪个区间内可作为最小值存在. 正向扫描,求出a[i]可做为最小值的区间的左边界 反向扫描,求出a[i]可作为最小值的区间的右边界 r[i] - l[i] +1 就 ...

  2. 51nod 1437 迈克步——单调栈

    有n只熊.他们站成一排队伍,从左到右依次1到n编号.第i只熊的高度是ai. 一组熊指的队伍中连续的一个子段.组的大小就是熊的数目.而组的力量就是这一组熊中最小的高度. 迈克想知道对于所有的组大小为x( ...

  3. 51nod 1437:迈克步 单调栈基础题

    1437 迈克步 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 有n只熊.他们站成一排队伍,从左到右依次1到 ...

  4. 51nod 1437 迈克步

    题目链接 先利用单调栈or其他方法找到一个元素g[i]作为最小值的区间,设为[L, R]. 那么长度为R-L+1的组的最大值ans=max(ans,g[i]).但是有一个问题: 比如6这个元素是长度为 ...

  5. 51nod1437 迈克步 单调栈

    考虑一个点作为最小值的区间$[L[i], R[i]]$ 那么这个区间的所有含$i$的子区间最小值都是$v[i]$ 因此,用单调栈求出$L[i], R[i]$后,对$R[i] - L[i] + 1$这个 ...

  6. 51nod 1102 【单调栈】

    思路: 对于这个高度往左能延伸最远x,往右能延伸最远y,(x+1+y)*w; 利用单调栈就行了: #include <cstdio> #include <stack> #inc ...

  7. 51nod 1102 面积最大的矩形 (单调栈)

    链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 思路: 首先介绍下单调栈的功能:利用单调栈,可以找到从左/ ...

  8. 51nod 1102 面积最大的矩形(单调栈)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 题意: 思路: 做法就是求出每个长方形向左向右所能延伸的最大距离. ...

  9. 51nod 1215 单调栈/迭代

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1215 1215 数组的宽度 题目来源: Javaman 基准时间限制:1 ...

随机推荐

  1. Presto 学习参考资料

    Presto 文档资料: 0.1版:Presto 0.100 Documentation 0.213版:Presto 0.213 Documentation 阿里云 presto 学习资料:https ...

  2. highchart应用示例1--2个不同类型变量2个y轴

    1.ajax调用接口和处理数据 function getCityData() { var date1 = $('#datetimepicker1').val(); var date2 = $('#da ...

  3. python中的logger模块

    logger 提供了应用程序可以直接使用的接口handler将(logger创建的)日志记录发送到合适的目的输出filter提供了细度设备来决定输出哪条日志记录formatter决定日志记录的最终输出 ...

  4. 常用的node.js模块

    一.url模块1.url.parse:将一个url转换成一个对象 1)参数1:url 2)参数2:布尔值 3)如果参数2是一个true的情况下会将query解析成一个对象2.url.format:将一 ...

  5. Eloquent JavaScript #13# HTTP and Forms

    索引 Notes fetch form focus Disabled fields form’s elements property 阻止提交 快速插入单词 实时统计字数 监听checkbox和rad ...

  6. VIM编码检查

    trouble shooting https://www.django.cn/article/show-4.html https://blog.csdn.net/lh756437907/article ...

  7. Golang指针基本介绍及使用案例

    一.指针的相关概念说明 变量:是基本类型,变量存的就是值,也叫值类型 地址:用于引用计算机的内存地址,可理解为内存地址的标签,通俗一点讲就是一间房在小区里的门牌号.如下图① 指针:指针变量存的是一个地 ...

  8. 使用nc命令传输文件和文件夹

    相比较常用的scp,nc命令传文件不需要建立ssh连接和输入密码,方便快捷:尤其是在只能用key登录的机器上: 传文件: 先在目标机器执行命令准备好接收(1221为任意可用端口) nc -l 1221 ...

  9. 关于使用spring mvc或者resteasy构建restful服务的差别与比较

    resteasy 是 jboss的一个开源java api for restful service(JSR 311,sun 2008年发布,最新GA版本是2.0, JAX-RS 2.0 (JSR-33 ...

  10. linux 压缩工具

    gzip gunzip zcat bzip2 bunzip2 bzcat xz unxz xzcat a:  gzip 用法 # gzip file  压缩文件 不会保留源文件 直接生成 file.g ...