首先这肯定是一道LIS的变形,这次求的是方案,还要求字典序最小
(注意这个字典序最小是指下标最小而不是数最小)
首先预处理以每个数为首,能组成多长的上升序列(这里我们用单调队列解决)
然后按照位置顺序扫一遍顺出可行即可
要注意每行末的空格
var f,a,q:array[..] of longint;
n,k,i,x,j,t,l,r,m:longint;
begin
readln(n);
for i:= to n do
read(a[i]);
a[]:=;
for i:=n downto do
begin
if (a[q[t]]>a[i]) then
begin
inc(t);
q[t]:=i;
f[i]:=t;
end
else begin
l:=;
r:=t;
while l<=r do
begin
m:=(l+r) shr ;
if (a[q[m]]<=a[i]) and (a[q[m-]]>a[i]) then break;
if (a[q[m]]<=a[i]) then r:=m- else l:=m+;
end;
f[i]:=f[q[m]];
q[m]:=i;
end;
end;
readln(k);
for i:= to k do
begin
readln(x);
j:=;
t:=-;
while (j<=n) and (x>) do
begin
if (f[j]>=x) and (a[j]>t) then
begin
write(a[j]);
if x<> then write(' ');
dec(x);
t:=a[j];
end;
inc(j);
end;
if x> then writeln('Impossible')
else writeln;
end;
end.