poj 2796
来源:互联网 发布:外立面效果图制作软件 编辑:程序博客网 时间:2024/06/05 06:28
单调栈经典题目
#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;const int maxn=1e5+10;int le[maxn],stack[maxn],top,l,r,n,a[maxn];ll sum[maxn],t,ans;int main(){ while(scanf("%d",&n)!=EOF){ ans=-1; memset(sum,0,sizeof(sum)); top=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; } a[++n]=-1; for(int i=1;i<=n;i++) { if(top==0||a[i]>a[stack[top-1]]) { le[i]=i; stack[top++]=i; continue; } if(a[i]==a[stack[top-1]]) continue; while(top>=1&&a[i]<a[stack[top-1]]) { top--; t=1LL*a[stack[top]]*(sum[i-1]-sum[le[stack[top]]-1]); if(t>ans) { ans=t; l=le[stack[top]]; r=i-1; } } le[i]=le[stack[top]]; stack[top++]=i; } printf("%lld\n%d %d\n",ans,l,r); } return 0;}
0 0
- POJ 2796
- poj 2796
- poj 2796
- POJ 2796
- poj 2796
- poj 2796
- poj 2796
- poj 2796 数字求和
- poj 2796 Feel Good
- poj 2796#单调栈
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ 2796 单调栈~
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- modbus与RS485
- ubuntu 安装升级java jdk 版本
- AndroidStudio打包的时候出现错误
- Spring的IOC、Spring对象初始化bean时机、Spring容器生命周期
- linux下MPI开发环境搭建
- poj 2796
- Servlet中Response对象应用1(输出简单文字、实现文件下载)
- 使用Picasso加载图片的内存优化实践
- 食君之禄,忠君之事
- thinkphp5 使用soap调用接口
- Retrofit 学习记录(一)
- 题目1007:奥运排序问题
- 设计模式之单例模式讲解
- 团体程序设计天梯赛L2-017 人以群分