和题解对过了,想尽办法都没 hack 掉这代码,第一个点就挂了
#include<cstdio>
#include<cstring>
using namespace std;
#define il inline
#define ri register int
long long n,stack[100010],w[100010],tot,maxx=-1,tmp[100010];
void Submain()
{
memset(stack,0,sizeof(stack));
memset(w,0,sizeof(w));
memset(tmp,0,sizeof(tmp));
tot=0,maxx=-1;
for(int i=1;i<=n;i++)
{
scanf("%lld",&tmp[i]);
}
for(int i=1;i<=n+1;i++)
{
if(tmp[i]>=stack[tot]) {++tot;stack[tot]=tmp[i];w[tot]=1;}
else{
int width=0;
while(tmp[i]<stack[tot])
{
width+=w[tot];
if(width*stack[tot]>maxx) maxx=width*stack[tot];
tot--;
}
stack[++tot]=tmp[i];w[tot]=width+1;
}
}
printf("%lld\n",maxx);
}
int main()
{
scanf("%lld",&n);
while(n){Submain();scanf("%lld",&n);}
return 0;
}