题目链接


Solution

直接考虑单调栈处理出每一个点作为最小值的区间长度.

然后 \(O(n)\) 找一遍最大值即可. 记得开 long long,以及要注意 \(0\) 的问题.

Code

#include<bits/stdc++.h>
#define ll long long
#define N 2000001
#define in(x) x=read()
using namespace std; ll n,a[N];
ll L[N],R[N],sta[N],top; ll read()
{
char ch=getchar();ll f=1,w=0;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){w=w*10+ch-'0';ch=getchar();}
return f*w;
} int main()
{
in(n);
for(ll i=1;i<=n;i++) in(a[i]);
for(ll i=1;i<=n;i++)
{
if(a[i]==0){L[i]=i;continue;}
if(a[sta[top]]<a[i]){sta[++top]=i,L[i]=i-1;continue;}
while(a[sta[top]]>=a[i])top--;
L[i]=sta[top]; sta[++top]=i;
}top=0;
for(ll i=n;i>=1;i--)
{
if(a[i]==0){R[i]=i;continue;}
if(a[sta[top]]<a[i]){sta[++top]=i,R[i]=i+1;continue;}
while(a[sta[top]]>=a[i])top--;
R[i]=sta[top]; if(top==0)R[i]=n+1;
sta[++top]=i;
}
ll ans=0;
for(ll i=1;i<=n;i++)
//cout<<L[i]<<' '<<R[i]<<endl;
ans=max(ans,a[i]*(R[i]-L[i]-1));
cout<<ans<<endl; }

最新文章

  1. Alljoyn瘦客户端库介绍(官方文档翻译)
  2. Hp自学整理html
  3. java12-6 冒泡排序法和选择排序法
  4. hadoop 序列化源码浅析
  5. python正则表达式例子说明
  6. BZOJ:4816: [Sdoi2017]数字表格
  7. springboot 返回json字符串格式化问题
  8. DRF框架之 用户角色权限与访问频率的权限设置
  9. MySQL-查询结果缓存
  10. 第二章 STM32的结构和组成
  11. 推荐一个好工具:P/Invoke Interop Assistant【转】
  12. 安卓constraintLayout中app:srcCompat设置的图片显示不出来
  13. Windows下修改Tomcat黑窗口标题
  14. 深入理解 mysql 索引
  15. WebSlides - 轻松制作漂亮的 HTML 幻灯片(演讲稿)
  16. asserts文件存到外部SD卡里
  17. JDBC事务提交/回滚实例
  18. Matlab——filter函数用法
  19. B. Vile Grasshoppers
  20. RocketMQ之NameServer学习笔记

热门文章

  1. 解决php文字及图片显示乱码的问题
  2. 课时68.id选择器(掌握)
  3. 简单的for循环实现九九乘法表
  4. 3、springboot配置文件占位符
  5. [Codeforces967C]Stairs and Elevators(二分查找)
  6. ListView, GirldList 等setCurrentItem 不立即刷新
  7. loj2174 「FJOI2016」神秘数
  8. 找出Xcode没有使用的图片
  9. 【Python】python模块加载
  10. (转\整)UE4游戏优化 多人大地型游戏的优化(四)内存的优化