- 最大矩形
- 2013-11-02 09:11:21 @
var
n,i,w:longint;
ans:int64;
d,dd,a,b,f:array[0..200000]of longint;
begin
while not seekeof do
begin
read(n);
ans:=0;
w:=0;
d[0]:=-maxlongint;
dd[0]:=0;
for i:=1 to n do read(a[i]);
readln;
for i:=1 to n do
begin
while a[i]<d[w] do
begin
if (i-dd[w])*d[w]>ans then
ans:=(i-dd[w])*d[w];
f[dd[w]]:=(i-dd[w])*d[w];
dec(w);
end;
inc(w);
d[w]:=a[i];
dd[w]:=i;
end;
for i:=1 to w do
begin
if (n-dd[i]+1)*d[i]>ans then
ans:=(n-dd[i]+1)*d[i];
f[dd[w]]:=(n-dd[w]+1)*d[w];
end;
w:=0;
for i:=1 to n do
b[i]:=a[n-i+1];
a:=b;
for i:=1 to n do
begin
while a[i]<d[w] do
begin
if (i-dd[w])*d[w]>ans then
ans:=(i-dd[w])*d[w];
inc(f[dd[w]],(i-dd[w])*d[w]-d[w]);
if f[dd[w]]>ans then ans:=f[dd[w]];
dec(w);
end;
inc(w);
d[w]:=a[i];
dd[w]:=i;
end;
for i:=1 to w do
begin
if (n-dd[i]+1)*d[i]>ans then
ans:=(n-dd[i]+1)*d[i];
inc(f[dd[w]],(n-dd[w])*d[w]);
if f[dd[w]]>ans then ans:=f[dd[w]];
end;
writeln(ans);
end;
writeln(0);
end.
写的有点恶心的单调队列,求大牛帮看一下。。wa
1 条评论
-
w_ypl LV 10 @ 2013-11-02 15:34:09
已解决。
- 1