题面:

大致思路: 单调栈求对于某个点左侧比其小的第一个值位置与右侧比其小的第一个值位置
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,a[maxn],l[maxn],r[maxn],stk[maxn],top;
int main() {
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i];
}
for(int i=1;i<=n;i++) {
while(a[stk[top]]>=a[i] && top) {
top--;
}
l[i]=stk[top];
stk[++top]=i;
}
memset(stk,0,sizeof(stk));
for(int i=1;i<=n;i++) {
r[i]=n+1;
}
for(int i=n;i>=1;i--) {
while(a[stk[top]]>=a[i] && top) {
top--;
}
if(stk[top]!=0) {
r[i]=min(r[i],stk[top]);
}
stk[++top]=i;
}
// for(int i=1;i<=n;i++) {
// cout<<l[i]<<" ";
// }
// cout<<endl;
// for(int i=1;i<=n;i++) {
// cout<<r[i]<<" ";
// }
// cout<<endl;
int ans=0;
for(int i=1;i<=n;i++) {
ans=max(ans,a[i]*(r[i]-l[i]-1));
}
cout<<ans<<endl;
return 0;
}
多谢