-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (41 loc) · 810 Bytes
/
Copy pathmain.cpp
File metadata and controls
51 lines (41 loc) · 810 Bytes
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
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int bi(int *arr, int n, int com)
{
int start = 0;
int end = n;
int middle;
while(end - start >= 0){
middle = (start + end)/2;
if(arr[middle] == com){
return 1;
}
else if(arr[middle] >= com ){
end = middle-1;
}
else{
start = middle+1;
}
}
return 0;
}
int main() {
int n,m;
scanf("%d", &n);
int* A = new int[n];
for(int i=0; i<n; i++){
scanf("%d", &A[i]);
}
scanf("%d", &m);
int* B = new int[m];
for(int i=0; i<m; i++){
scanf("%d", &B[i]);
}
sort(A, A + n);
for(int i=0; i<m; i++){
printf("%d\n", bi(A, n-1, B[i]));
}
return 0;
}