比赛 |
20111021 |
评测结果 |
AAAAAA |
题目名称 |
黑盒子 |
最终得分 |
100 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-10-21 21:13:41 |
显示代码纯文本
program heixiazi;
var
size,a,u,left,right,jilu:array[0..30000]of longint;
root,now,i,n,m,k,ans:longint;
procedure insert(t,v:longint);
begin
inc(size[t]);
if v>a[t] then
begin
if right[t]=0 then
begin
right[t]:=now;
size[now]:=1;
exit
end
else
insert(right[t],v)
end
else
begin
if left[t]=0 then
begin
left[t]:=now;
size[now]:=1;
exit
end
else
insert(left[t],v)
end
end;
procedure find(t,k:longint);
begin
if size[left[t]]+1=k then
begin
ans:=a[t];
exit
end
else
begin
if size[left[t]]+1<k then
find(right[t],k-size[left[t]]-1)
else
find(left[t],k)
end
end;
begin
assign (input,'blackbox.in');
reset (input);
assign (output,'blackbox.out');
rewrite (output);
readln (n,m);
for i:=1 to n do
read (a[i]);
readln;
for i:=1 to m do
begin
read (u[i]);
inc(jilu[u[i]])
end;
root:=1;
now:=1;
size[1]:=1;
while jilu[1]>0 do
begin
inc(k);
find(root,k);
writeln (ans);
dec(jilu[1])
end;
for i:=2 to n do
begin
inc(now);
insert(root,a[i]);
while jilu[i]>0 do
begin
inc(k);
find(root,k);
writeln (ans);
dec(jilu[i])
end;
end;
close (input);
close (output)
end.