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
| #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[200200],b[200200];
int main() {
int T;
scanf("%d",&T);
while(T--) {
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int n,m;
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++) {
int t;
scanf("%d",&t);
a[t]=1;
}
int cnt=0;
for(int i=0; i<200020; i++)
if(!a[i])
b[cnt++]=i;
while(m--) {
int t;
scanf("%d",&t);
if(!a[t]) {
printf("%d\n",t);
continue;
}
int l=0,r=cnt;
while(l<=r) {
int mid=(l+r)/2;
if(b[mid]>=t)
r=mid-1;
else
l=mid+1;
}
printf("%d\n",b[l]);
}
}
return 0;
}
|