记录编号 117898 评测结果 AAAAAAAAAA
题目名称 [HAOI 2007]上升序列 最终得分 100
用户昵称 Gravatar0-0 是否通过 通过
代码语言 Pascal 运行时间 1.089 s
提交时间 2014-09-02 21:27:47 内存使用 0.28 MiB
显示代码纯文本
var
  f,a,d:array[1..10000]of longint;
  l,r,x,i,j,n,s,t,m:longint;
begin
  assign(input,'lis.in');
  assign(output,'lis.out');
  rewrite(output);
  reset(input);
  read(n);
  for i:=1 to n do
    read(a[i]);
  f[n]:=1;
  d[1]:=a[n];
  s:=1;
  for i:=n-1 downto 1 do
    begin
      l:=1;
      r:=s;
      m:=(l+r+1)>>1;
      while l<r do
        begin
          if d[m]>a[i] then l:=m
          else r:=m-1;
          m:=(l+r+1)>>1;
        end;
       if d[m]>a[i] then
         begin
           f[i]:=m+1;
           if s<m+1 then begin s:=m+1; d[s]:=a[i]; end
           else if d[m+1]<a[i] then d[m+1]:=a[i];
         end;
    end;
  {for i:=1 to n do
    write(f[i],' ');}
  read(m);
  for j:=1 to m do   begin
    read(x);
    if (x<=0)or(x>s) then writeln('Impossible')
    else
      begin
        i:=1; t:=-maxlongint;
        while (x>0)and(i<=n) do
          begin
            if (f[i]>=x)and(a[i]>t) then
              begin write(a[i],' '); t:=a[i]; dec(x); end;
            inc(i);
          end;
        writeln;  //writeln(j);writeln;
      end;
  end;
  close(input);
  close(output);
end.