So far no source has been found, but there happens to be a set of test data, the lack of test data of the person can ask me to. The classic monotone queue, this blog post is very clear, I will not elaborate.
1#include <iostream>2#include <cstdio>3#include <queue>4#include <cstring>5 6 using namespacestd;7 Const intmaxn=400000;8 intLLEN[MAXN],RLEN[MAXN],Q[MAXN];9 __int64 H[MAXN];Ten intN; One A voidinput () - { - thescanf"%d",&n); - for(intI=0; i<n;i++) scanf ("%lld",&h[i]); - } - + voidCountleft () - { +q[0]=-1; A intRear=1; at for(intI=0; i<n;i++) - { - while(rear>1&& h[q[rear-1]]>=h[i]) rear--; -llen[i]=i-q[rear-1]-1; -q[rear]=i; -rear++; in } - } to + voidcountright () - { theq[0]=N; * intRear=1; $ for(inti=n-1; i>=0; i--) Panax Notoginseng { - while(rear>1&& h[q[rear-1]]>=h[i]) rear--; therlen[i]=q[rear-1]-i-1; +q[rear]=i; Arear++; the } + } - $ voidoutput () $ { -__int64 ans=0; - for(intI=0; i<n;i++) theAns=max (ans, (llen[i]+rlen[i]+1)*h[i]); -cout<<ans<<Endl;Wuyi } the - intMain () Wu { -Freopen ("Mr452.in4","R", stdin); AboutFreopen ("Mr452.ou4","W", stdout); $ input (); - countleft (); - countright (); - output (); A return 0; +}
"Monotonous queue" advertising printing