bawang51吧 关注:31贴子:3,169
  • 1回复贴,共1

【OI】单调队列

只看楼主收藏回复

var a,b:array[1..10000]of longint;
i,s,t,n,m,k,x:longint;
begin
readln(n);
readln(k);
readln(a[1]);
writeln(a[1]);
b[1]:=1;
s:=1;
t:=1;
for i:=2 to n do
begin
readln(x);
while (a[t]>x) and (t>0) do
t:=t-1;
t:=t+1;
a[t]:=x;
b[t]:=i;
while b[s]<=i-k do
s:=s+1;
writeln(a[s]);
end;
end.



IP属地:上海1楼2011-08-11 19:06回复
    楼上果然有问题,今天才发现
    var a,b:array[1..10000]of longint;
    i,s,t,n,m,k,x:longint;
    begin
    readln(n);
    readln(k);
    readln(a[1]);
    writeln(a[1]);
    b[1]:=1;
    s:=1;
    t:=1;
    for i:=2 to n do
    begin
    readln(x);
    while (t>0) and (a[t]>x) do
    t:=t-1;
    t:=t+1;
    a[t]:=x;
    b[t]:=i;
    while b[s]<=i-k do
    s:=s+1;
    writeln(a[s]);
    end;
    end.
    


    IP属地:上海2楼2012-07-29 21:06
    回复