题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102

题意:中文题诶~

思路:单调栈/预处理 (这篇博客就不细写了啦,只给出代码和转过来的两篇不错的题解,好困了~)

单调栈:http://blog.csdn.net/u012773338/article/details/40265223

代码:

#include <iostream>
#include <stack>
#define ll long long
#define MAXN 50010
using namespace std; ll a[MAXN], ans=;
stack<int> st; int main(void){
ios::sync_with_stdio(false), cin.tie(), cout.tie();
int n;
cin >> n;
for(int i=; i<n; i++){
cin >> a[i];
}
a[n]=-;
for(int i=; i<=n; i++){
if(st.empty()||a[i]>=a[st.top()]){
st.push(i);
}else if(a[i]<a[st.top()]){
int cnt;
while(!st.empty()&&a[i]<a[st.top()]){
ans=max(ans, a[st.top()]*(i-st.top()));
cnt=st.top();
st.pop();
}
st.push(cnt);
a[cnt]=a[i];
}
}
cout << ans << endl;
return ;
}

预处理:http://blog.csdn.net/queuelovestack/article/details/52326276

代码:

 #include <iostream>
#define ll long long
#define MAXN 50010
using namespace std; ll l[MAXN], r[MAXN], a[MAXN]; int main(void){
ios::sync_with_stdio(false), cin.tie(), cout.tie();
int n;
cin >> n;
for(int i=; i<=n; i++){
cin >> a[i];
}
for(int i=; i<=n; i++){
int k=i-;
while(a[i]<=a[k]){
k=l[k]-;
}
l[i]=k+;
}
for(int i=n; i>; i--){
int k=i+;
while(a[i]<=a[k]){
k=r[k]+;
}
r[i]=k-;
}
ll ans=;
for(int i=; i<=n; i++){
ans=max((r[i]-l[i]+)*a[i], ans);
}
cout << ans << endl;
}

51nod1102(单调栈/预处理)的更多相关文章

  1. [51nod1102]面积最大的矩形(单调栈||预处理)

    题意:求序列上某区间最小值乘区间长度的最大值. 解题关键:很早就在<挑战程序设计竞赛>中见过了,单调栈模板题,注意弹栈时如何处理后面的元素. 法一:单调栈 #include<bits ...

  2. BZOJ4540 Hnoi2016 序列 【莫队+RMQ+单调栈预处理】*

    BZOJ4540 Hnoi2016 序列 Description 给定长度为n的序列:a1,a2,-,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,-,ar- ...

  3. Gym 100971D Laying Cables 单调栈

    Description One-dimensional country has n cities, the i-th of which is located at the point xi and h ...

  4. Code Forces Gym 100971D Laying Cables(单调栈)

    D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  5. bzoj 4826: [Hnoi2017]影魔 [主席树 单调栈]

    4826: [Hnoi2017]影魔 题意:一个排列,点对\((i,j)\),\(p=max(i+1,j-1)\),若\(p<a_i,a_j\)贡献p1,若\(p\)在\(a_1,a_2\)之间 ...

  6. BZOJ.4540.[HNOI2016]序列(莫队/前缀和/线段树 单调栈 RMQ)

    BZOJ 洛谷 ST表的一二维顺序一定要改过来. 改了就rank1了哈哈哈哈.自带小常数没办法. \(Description\) 给定长为\(n\)的序列\(A_i\).\(q\)次询问,每次给定\( ...

  7. bzoj 4540 [HNOI 2016] 序列 - 莫队算法 - Sparse-Table - 单调栈

    题目传送门 传送点I 传送点II 题目大意 给定一个长度为$n$的序列.询问区间$[l, r]$的所有不同的子序列的最小值的和. 这里的子序列是连续的.两个子序列不同当且仅当它们的左端点或右端点不同. ...

  8. 【CF815D】Karen and Cards 单调栈+扫描线

    [CF815D]Karen and Cards 题意:一张卡片有三个属性a,b,c,其上限分别为A,B,C,现在有n张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...

  9. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

随机推荐

  1. 使用urllib2打开网页的三种方法(Python2)

    python2才有urllib2模块,python3把urllib和urllib2封装成了urllib模块 使用urllib2打开网页的三种方法 #coding:utf-8 import urllib ...

  2. View 视图动画基础

  3. SQLSERVER安装记录

    很多人都喜欢重装编程环境,VS,SQL是最常见的 尤其是SQL,在删除所有的SQL相关的组件之后(360),记得再次打开控制面板,查看是否有漏掉的,本人就有一个SQLXML没有删除掉 在删除之后,清理 ...

  4. ActiveMQ之发布、订阅使用

    maven依赖 <dependencies> <dependency> <groupId>org.apache.activemq</groupId> & ...

  5. python无法安装cv2的解决办法

    问题:在windows命令窗口输入pip install cv2后出现:Could not find a version that satisfies the requirement cv2... 解 ...

  6. 分享知识-快乐自己:SpringMvc后台Date对象数据 到 前台页面的显示转换

    常常为日期格式的转换而烦恼吗?那么就试试看看楼主的方式吧!让你摆脱烦恼,从而快乐撸码. 如果你只用作于一个日期的显示采用方式如下: 导入:相应的类库 <%@ taglib uri="h ...

  7. listen 66

    Frog Species Found in Big Apple Scientists discover new species all the time—on the order of 15,000 ...

  8. android自定义控件(二) 入门,继承View

    转载请注明地址:http://blog.csdn.net/ethan_xue/article/details/7313788 ps: 可根据apidemo里LableView,list4,list6学 ...

  9. 从CWnd::GetSafeHwnd实现得到的知识

    在看MFC源码的过程中,有个地方一直不解,看如下代码 BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWO ...

  10. NO0:重新拾起C语言

    因工作所需,重新捡起C语言,之前在学校里有接触过,但现在已经忘的一干二净了,现决定重新开始学习,为工作,为生活. 以<标准 C程序设计 第5版>的课程进行基础学习,同时以另外两本书为辅助, ...