比赛 20101110 评测结果 WWWWWWWWWW
题目名称 滑动窗口 最终得分 0
用户昵称 belong.zmx 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 21:45:20
显示代码纯文本
program windows(input,output);
var
 i,j:longint;
 a:array[0..1000000]of longint;
 f,g:array[0..1000000]of longint;
 f1,g1:array[0..1000000]of longint;
 n,k,p:longint;

begin
 assign(input,'window.in');
 reset(input);
 readln(n,k);
 for i:=1 to n do read(a[i]);
 close(input);

 a[0]:=maxlongint;
 for i:=2 to n do
 begin
  p:=i-1;
  if a[i]=a[p] then
  begin
   f[i]:=f[p];
   continue;
  end;
  if a[i]<a[p] then
  begin
   f[i]:=p;
   continue;
  end;
  while a[p]<a[i] do p:=f[p];
  if a[p]=a[i] then
  begin
   f[i]:=f[p];
   continue;
  end;
  if a[p]<a[i] then f[i]:=p;
 end;

 a[0]:=-maxlongint;
 for i:=2 to n do
 begin
  p:=i-1;
  if a[i]=a[p] then
  begin
   g[i]:=g[p];
   continue;
  end;
  if a[i]>a[p] then
  begin
   g[i]:=p;
   continue;
  end;
  while a[p]>a[i] do p:=g[p];
  if a[p]=a[i] then
  begin
   g[i]:=g[p];
   continue;
  end;
  if a[p]<a[i] then g[i]:=p;
 end;

 for i:=k to n do
 begin
  p:=i;
  while (f[p]<>0)and(f[p]>=i-k+1) do p:=f[p];
  f1[i-k+1]:=a[p];
  p:=i;
  while (g[p]<>0)and(g[p]>=i-k+1) do p:=g[p];
  g1[i-k+1]:=a[p];
 end;

 assign(output,'window.out');
 rewrite(output);
 for i:=1 to n-k do write(g1[i],' ');
 writeln(g1[i+1]);
 for i:=1 to n-k do write(f1[i],' ');
 writeln(f1[i+1]);
 close(output);
end.