-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUMMER_Lab01_4.c
66 lines (54 loc) · 1.05 KB
/
SUMMER_Lab01_4.c
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
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<stdlib.h>
int arr[10000001];
int arr2[10000001];
int compare(const void* first, const void* second)
{
int a = *(int*)first;
int b = *(int*)second;
return (a > b) - (a < b);
}
int binary_search(int arr[], int len, int key)
{
int l = 0;
int r = len - 1;
int m;
while (l <= r)
{
m = l + (r - l) / 2;
if (key == arr[m])
return 1;
else if (key < arr[m])
r = m - 1;
else
l = m + 1;
}
return 0;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
qsort(arr, n, sizeof(int), compare);
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++)
{
scanf("%d", &arr2[j]);
}
for (int i = 0; i < m; i++)
{
int ans = binary_search(arr, n, arr2[i]);
printf("%d\n", ans);
}
}
return 0;
}