poj 2796Feel Good
来源:互联网 发布:淘宝首页源代码下载 编辑:程序博客网 时间:2024/05/19 12:16
这道题师姐说用单调栈。。
所以顺便学了一下单调栈。。
建一个单调递增的队列。。
每个元素进来时在队尾t人,比他小就t。。然后插入。。
对于每一个队列里的元素,以他为最小值的一段区间,肯定是:
队列前面的一个数在原数组的位置+1
到
队列后面的一个数在原数组的位置-1
用结构体记录位置和值这道题就可以了
#include<cstdio>#include<iostream>#include<cstring>using namespace std;long long a[110000];struct node { long long x,t;}sta[110000];int top;long long s[110000];int main() { int n; while(scanf("%d",&n)!=EOF) { s[0]=0;long long mmin=99999999; for(int i=1;i<=n;i++) { scanf("%I64d",&a[i]);s[i]=s[i-1]+a[i]; mmin=min(mmin,a[i]); } a[++n]=mmin-1; top=0;long long ans=0; long long x=1,y=1;sta[0].x=-1;sta[0].t=0; for(long long i=1;i<=n;i++) { node ss;ss.x=a[i];ss.t=i; while(ss.x<sta[top].x&&top>0) { long long tt=(s[ss.t-1]-s[sta[top-1].t])*sta[top].x; if(tt>ans) { ans=tt; x=sta[top-1].t+1; y=ss.t-1; } top--; } sta[++top]=ss; } printf("%I64d\n%I64d %I64d\n",ans,x,y); } return 0;}
0 0
- poj 2796 Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- Poj-2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796Feel Good
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- POJ 2796 Feel Good
- stm8函数传入形参值改变了
- CodeForces 340C
- [Unity5.3.6与APK]CommandInvokationFailure:Unable to convert classes into dex format错误的解决
- 线上问题排查
- swift中字面量的定义使用
- poj 2796Feel Good
- MasterCAM 9.1 2D制图绘制 点线面
- 你必须知道的.NET之特性和属性
- 不懂技术不要对懂技术的人说这很容易实现
- pywin32模块安装方法
- 【Leetcode】401. Binary Watch
- 加快Android Studio编译速度 减少gradle时间
- [BZOJ1008][HNOI2008]越狱
- CSS3 小动画