69,371
社区成员
发帖
与我相关
我的任务
分享
# include<stdio.h>
# include<string.h>
int heap[100001],b[100001],all=0;
void insert(int x)
{
heap[all] = x;
all++;
int s,p = all-1,t;
while(p>0)
{
s = (p-1)/2;
if(heap[s]<heap[p])
{
t = heap[s];
heap[s] = heap[p];
heap[p] = t;
p = s;
}
else break;
}
}
void del()
{
heap[0] = heap[all-1];
all--;
int i,s=0,t;
for(i=1;i<all;i=2*s+1)
{
if(heap[i]<heap[i+1] && i+1<all) i++;
if(heap[s]>=heap[i]) break;
t = heap[s];
heap[s] = heap[i];
heap[i] = t;
s = i;
}
}
int main()
{
int n,i,t,x,q,j;
scanf("%d",&t);
while(t--)
{
all = 0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
scanf("%d",&q);
for(i=1,j=0;i<=q;i++)
{
scanf("%d",&x);
while(j<x)
{
insert(b[j]);
j++;
}
printf("%d",heap[0]);
if(j<n)printf(" ");
del();
}
printf("\n");
}
return 0;
}