比赛 NOIP_1 评测结果 AAAAAAAAAA
题目名称 画展 最终得分 100
用户昵称 zpl123 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-12 12:07:20
显示代码纯文本
program exhibit;
const
maxn=1000000;
maxm=2000;
var
data:array[1..maxn] of integer;
x:array [1..maxm] of longint;
num,i,j,a,b,max,n,m:longint;

procedure init;
var
i,j:longint;
begin
assign(input,'exhibit.in');
reset(input);
assign(output,'exhibit.out');
rewrite(output);
readln(n,m);
for i:=1 to n do read(data[i]);
close(input);
end;

procedure main;
begin
  i:=1;
  j:=1;
  x[data[j]]:=1;
  num:=1;
  max:=n;
  a:=1;
  b:=n;
  while j<=n do
   begin
    if num=m then
    begin
    if j-i+1<max then
     begin
     a:=i;
     b:=j;
     max:=j-i+1;
     end;
     inc(i);
     dec(x[data[i-1]]);
     if x[data[i-1]]=0 then dec(num);
    end
    else begin
    inc(j);
    if x[data[j]]=0 then inc(num);
    inc(x[data[j]]);
         end;
    end;
end;

procedure print;
begin
writeln(a,' ',b);
close(output);
end;

begin
init;
main;
print;
end.