这题做法很多
可以通过类似noi超级钢琴那道题目的做法用可持久化+trie来做
还可以直接在trie树上维护size域然后类似查找k大的做法做
总之还是比较水的
type node=record
kth,num,ans:longint;
end; var heap:array[..] of node;
son:array[..,..] of longint;
size:array[..] of longint;
a:array[..] of longint;
t,i,n,m:longint; procedure swap(var a,b:node);
var c:node;
begin
c:=a;
a:=b;
b:=c;
end; procedure add(x:longint);
var i,p,y:longint;
begin
p:=;
for i:= downto do
begin
y:=x and ( shl i);
if y> then y:=;
if son[p,y]= then
begin
inc(t);
son[p,y]:=t;
end;
p:=son[p,y];
inc(size[p]);
end;
end; function ask(x,k:longint):longint;
var p,i,y:longint;
begin
p:=;
ask:=;
for i:= downto do
begin
y:=x and ( shl i);
if y> then y:=;
if size[son[p,y]]>=k then p:=son[p,y]
else begin
ask:=ask+ shl i;
k:=k-size[son[p,y]];
p:=son[p,-y];
end;
end;
end; procedure sift(i:longint);
var j:longint;
begin
j:=i shl ;
while j<=t do
begin
if (j+<=t) and (heap[j].ans>heap[j+].ans) then inc(j);
if heap[i].ans>heap[j].ans then
begin
swap(heap[i],heap[j]);
i:=j;
j:=i shl ;
end
else break;
end;
end; begin
readln(n,m);
t:=;
for i:= to n do
begin
readln(a[i]);
add(a[i]);
end;
for i:= to n do
begin
heap[i].num:=a[i];
heap[i].kth:=;
heap[i].ans:=ask(a[i],);
end;
t:=n;
for i:=n div downto do
sift(i);
for i:= to *m do
begin
if i mod = then write(heap[].ans,' '); //注意会被重复计算
if heap[].kth=n then
begin
swap(heap[],heap[t]);
dec(t);
end
else begin
inc(heap[].kth);
heap[].ans:=ask(heap[].num,heap[].kth);
end;
sift();
end;
end.