-
Notifications
You must be signed in to change notification settings - Fork 0
/
00501.cpp
54 lines (50 loc) · 917 Bytes
/
00501.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int TC,m,n,x,l;
vector<int> arr,seq;
set<ii> s;
set<ii>::iterator sit;
scanf("%d",&TC);
while(TC--)
{
arr.clear(); seq.clear(); s.clear(); l = 0;
scanf("%d %d",&m,&n);
while(m--) scanf("%d",&x),arr.push_back(x);
while(n--) scanf("%d",&x),seq.push_back(x);
sort(seq.begin(),seq.end());
for(int i = 0,j = 0;i < arr.size();i++)
{
s.insert(ii(arr[i],i));
if(s.size() == 1) sit = s.find(ii(arr[i],i));
if(arr[i] < sit->first) sit--;
while(l)
{
sit++;
if(sit == s.end())
{
sit--;
break;
}
l--;
}
while(j < seq.size() && i+1 == seq[j])
{
printf("%d\n",sit->first);
j++;
sit++;
if(sit == s.end())
{
sit--;
l++;
}
}
}
if(TC) printf("\n");
}
return 0;
}