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. django 常用方法总结 < 手写分页-上传头像-redis缓存,排行 ...>

    1.不使用自带模块<Paginator>的手写分页功能views.pydef post_list(request): page = request.GET.get('page', 1) # ...

  2. mysql-day06

    ##视图 - 什么是视图:在数据库中存在多种对象,表和视图都是数据库中的对象,创建视图时名称不能和表重名,视图实际上就代表一段sql查询语句,也可以理解成视图是一张虚拟的表,此虚拟表中的数据会随着原表 ...

  3. linux--- sort,uniq,cut,wc命令

    1.sort [-fbMnrtuk] [file or stdin] -f :忽略大小写的差异,例如 A 与 a 视为编码相同: -b :忽略最前面的空格符部分: -M :以月份的名字来排序,例如 J ...

  4. Python进阶【第十一篇】模块(下)之常用模块

    内置模块是Python自带的功能,在使用内置模块相应的功能时,需要[先导入]再[使用] 一.time模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳 ...

  5. pyglet player sound

    Player = pyglet.media.Player() # our event handling function def on_eos(): print("on player eos ...

  6. socket编程-阻塞和非阻塞

    转自:https://www.cnblogs.com/sunziying/p/6501045.html 建立连接 阻塞方式下,connect首先发送SYN请求道服务器,当客户端收到服务器返回的SYN的 ...

  7. oracle 18c的版本号规则

    18C之后的版本标识 从2017年7月开始,Oracle改变了以往的数据库软件发布流程,采用年度Release和季度更新的策略. Yearly Release 将之前的N年一发布更改为每年一发布.每年 ...

  8. Bitbucket备份恢复

    我们需要备份什么? home directory:contains  repository data, log files, plugins, and so on. database:contains ...

  9. Codeforces 839B Game of the Rows - 贪心

    Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldie ...

  10. vc++读取文件属性的详细信息描述 通过读取QQ的注册表和EXE路径两种方式

    转载:http://www.cnblogs.com/pythonschool/archive/2012/10/18/2729872.html // File: GetFileVersion.cpp / ...