poj2796Feel Good 前缀和+单调栈经典例题

题意:求区间最小值乘区间和的最大值

题解:单调栈求左右边界,然后前缀和

#include 
using namespace std;
typedef long long ll;
const int maxn = 1e5+5, INF = 0x3f3f3f3f;
#define mod int(1e9+7)
#define pi acos(-1.0)
int n,top;
int a[maxn],sta[maxn],l[maxn],r[maxn];
ll sum[maxn];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    a[++n]=-1;
    top=0;ll ans=0;int ansl,ansr;
    for(int i=1;i<=n;i++){
        if(top==0||a[i]>a[sta[top-1]]){
            sta[top++]=i;
            l[i]=i;
            continue;
        }
        if(a[i]==a[sta[top-1]])continue;
        while(top>=1&&a[i]ans){
                ans=tmp;
                ansl=l[sta[top]];
                ansr=i-1;
            }
        }
        l[i]=l[sta[top]];
        sta[top++]=i;
    }
    //cout<

 

你可能感兴趣的:(单调栈,前缀和)