hdu 1506 最大矩阵面积 __int64 AC long long TLE

#include<cstdio>
#include<iostream>
using namespace std;
#define maxn 100005
int l[maxn],r[maxn],n;
__int64 h[maxn],ans;
int main()
{
    //freopen("//media/学习/ACM/input.txt","r",stdin);
    while(scanf("%d",&n),n)
    {
        int i,j;
        for(i=1;i<=n;i++)scanf("%I64d",&h[i]),l[i]=r[i]=i;
        h[0]=h[n+1]=-1;
        for(ans=h[1],i=2;i<=n;i++)
            while(h[l[i]-1]>=h[i])l[i]=l[l[i]-1];
        for(i=n-1;i>=1;i--)
            while(h[r[i]+1]>=h[i])r[i]=r[r[i]+1];
        for(i=1;i<=n;i++)
            if((h[i]*(r[i]-l[i]+1))>ans)ans=(h[i]*(r[i]-l[i]+1));
        printf("%I64d\n",ans);
    }
    return 0;
}

你可能感兴趣的:(hdu 1506 最大矩阵面积 __int64 AC long long TLE)