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

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

#include <bits/stdc++.h>
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]<a[sta[top-1]]){
            --top;
            ll tmp=1ll*a[sta[top]]*(sum[i-1]-sum[l[sta[top]]-1]);
            r[sta[top]]=i-1;
            if(tmp>ans){
                ans=tmp;
                ansl=l[sta[top]];
                ansr=i-1;
            }
        }
        l[i]=l[sta[top]];
        sta[top++]=i;
    }
    //cout<<l[2]<<" "<<r[2]<<endl;
    cout<<ans<<endl;
    cout<<ansl<<" "<<ansr<<endl;
}