传送门
题意:
一看图也能猜出来吧。。。
给一坨矩形,求最大矩形
单调栈模板题。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define LL long long
const int max_n=1e5+5;
LL n,h[max_n],Max,strack[max_n],temp;
struct hp{LL l,r;}f[max_n];
inline void insert(LL x){
while (h[strack[temp]]>=h[x]&&temp)
f[x].l=f[strack[temp]].l,f[strack[temp-1]].r=f[strack[temp]].r,--temp;
f[strack[temp]].r=f[x].r;
strack[++temp]=x;
}
int main(){
while (~scanf("%lld",&n)){
if (!n) return 0;
for (LL i=1;i<=n;++i) scanf("%lld",&h[i]),f[i].l=f[i].r=i;
for (LL i=1;i<=n;++i) insert(i);
while (temp) f[strack[temp-1]].r=f[strack[temp]].r,--temp;
Max=0;
for (int i=1;i<=n;++i)
Max=max(Max,(f[i].r-f[i].l+1)*h[i]);
printf("%lld\n",Max);
}
}
延伸的时候延伸到另一个点的l或r,不要只到这个点。