比赛 |
20101110 |
评测结果 |
AAAAATTTTT |
题目名称 |
滑动窗口 |
最终得分 |
50 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 21:44:30 |
显示代码纯文本
{窗口
RMQ
Author:yangbohua
Time:2010-11-10}
program windows;
var
min,max:array[0..1000010,0..21] of longint;
n,k,i,j,a:longint;
begin
assign(input,'window.in');
reset(input);
assign(output,'window.out');
rewrite(output);
readln(n,k);
for i:=1 to n do
begin
read(a);
min[i,0]:=a;
max[i,0]:=a;
end;
for i:=1 to trunc(ln(n)/ln(2)) do
for j:=1 to n-(1 shl i)+1 do
if min[j,i-1]<min[j+(1 shl (i-1)),i-1]
then min[j,i]:=min[j,i-1]
else min[j,i]:=min[j+(1 shl (i-1)),i-1];
j:=trunc(ln(k)/ln(2));
for i:=1 to n-k+1 do
if min[i,j]<min[i+k-1-(1 shl j)+1,j]
then write(min[i,j],' ')
else write(min[i+k-1-(1 shl j)+1,j],' ');
writeln;
for i:=1 to trunc(ln(n)/ln(2)) do
for j:=1 to n-(1 shl i)+1 do
if max[j,i-1]>max[j+(1 shl (i-1)),i-1]
then max[j,i]:=max[j,i-1]
else max[j,i]:=max[j+(1 shl (i-1)),i-1];
j:=trunc(ln(k)/ln(2));
for i:=1 to n-k+1 do
if max[i,j]>max[i+k-1-(1 shl j)+1,j]
then write(max[i,j],' ')
else write(max[i+k-1-(1 shl j)+1,j],' ');
writeln;
close(input);
close(output)
end.