Train of Thought: monotonous queue, opening two Arrays: stack [] and len [] stack [] storage input long len [] storage width. In the stack, you can add and store data by order. If you encounter data smaller than the stack [top], you need to delete the top element until it can be stored at the top after deletion, before deletion, check whether the ans (l + len [top]) * stack [top] and current ans are updated to obtain the maximum value to ans ), write down the value of len [top] And give l (l + = len [top]). The new len value is l + 1. For details, refer to the code.
AC code:
[Cpp]
/* This code is nyoj ac code. If you want to change long to _ int64 in hdu oj (change the output format accordingly), hdu oj does not support long */
# Include <stdio. h>
# Include <string. h>
# Define max (a, B) a> B? A: B
Int stack [2, 100010], len [2, 100010];
Int main ()
{
Int a, B, n, h;
While (scanf ("% d", & n)
{
Long top =-1, ans = 0;
For (a = 0; a <= n; a ++)
{
If (a <n)
Scanf ("% d", & h );
Else
H =-1;
If (top <0 | stack [top] {
Stack [++ top] = h;
Len [top] = 1;
}
Else
{
Int l = 0;
While (stack [top]> = h & top> = 0)
{
Ans = max (ans, (long) (len [top] + l) * stack [top]);
L + = len [top --];
}
If (h> 0)
{
Stack [++ top] = h;
Len [top] = 1 + l;
}
}
}
Printf ("% lld \ n", ans );
}
}
Author: PIAOYI0208