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. Codeforce 835A - Key races

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  2. 运行tomcat报Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]"

    解决方法1:   手动设置MaxPermSize大小,如果是linux系统,修改TOMCAT_HOME/bin/catalina.sh,如果是windows系统,修改TOMCAT_HOME/bin/c ...

  3. Centos7升级gcc学习笔记 gcc 4.8.5 -> gcc 5.4.0

    摘自:https://www.cnblogs.com/highway-9/p/5628852.html 一.安装开发必备环境: yum groupinstall "Development T ...

  4. 常用的node.js模块

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

  5. 每日linux命令学习-grep模式检索

    grep模式检索指令包括grep,egrep,和fgrep,.Linux系统使用正则表达式优化文本检索,所以在此,笔者首先学习了一下正则表达式. 1. 正则表达式 正则表达式使用被称为元字符(Meta ...

  6. Java笔记 #03# HtmlUnit爬虫

    存档留用 (= 存档留着备用) 爬的是一个开放的自动回复机器人 API 网站 http://i.itpk.cn/. 结构 大致如下: 我做的事情就是[输入文字,点击按钮,爬取内容],如上图所示. pa ...

  7. Django Form&ModelForm

    ModelForm: 首先导入所需模块 from django.forms import ModelFormfrom django.forms import widgets as form_widge ...

  8. linux交换区使用过多导致的性能问题

    近日,我们开发发现有一台配置相同的服务器跑的特别慢,相同数据量的情况下,其他服务器只要跑10分钟,这台服务器要跑50分钟,经确认,所有的应用层配置参数都相同.上去之后,发现该服务器swap使用比较多, ...

  9. 监控mysql状态脚本

    监控mysql状态, 发现宕后, 自动重启, 每秒检查一次. check.sh #!/bin/bash while [ true ]; do /bin/sleep 1 sh mysql_status. ...

  10. python之路-day1-if...else...流程判断

    判断输入的用户名:#Author:zww _username = "zww" _password = " username = input("username: ...