描述
输入
第一行给出一个数字T,代表T组数据 第二个先给出N,代表数列中有多少个数字,再给出M,代表M个询问。 N,M<=30000 第三行给出N个数字 第四行给出M个数字,b1,b2…bm,保证升序。 代表依次询问前b1中数字中第1小的数字是多少,前b2个数字中第2小的数字是多少,前b3个数字中第3小的数字是多少
输出
针对每个询问,输出结果。
样例
输入复制
1
7 4
1 3 2 4 5 9 8
2 3 4 5
输出复制
1
2
3
4
末尾几行是对输出格式的一个转换,记住要加上那个:
if(T>0)printf("\n");
因为在T>0时才有值输出,否则过不了。
#include<bits/stdc++.h>
using namespace std;
int a[30005],b[30005];
int n,m,j,T;
int main()
{
scanf("%d",&T);
while(T--)
{
priority_queue<int> q2;
priority_queue<int, vector<int>, greater<int> > q1;
j=1;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]);
for(int i=1;i<=m;i++)
{
for(;j<=b[i];j++)
q1.push(a[j]);
q2.push(q1.top());
q1.pop();
while(!q1.empty()&&q1.top()<q2.top())
{
int x=q1.top();
int y=q2.top();
q1.pop();
q2.pop();
q1.push(y);
q2.push(x);
}
printf("%d\n",q2.top());
}
if(T>0)printf("\n");
}
return 0;
}