求大牛帮看一下代码

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 条评论

  • 1

信息

ID
1580
难度
7
分类
数据结构 | 单调队列 点击显示
标签
递交数
906
已通过
190
通过率
21%
被复制
3
上传者