-
Notifications
You must be signed in to change notification settings - Fork 0
/
10815.cpp
46 lines (41 loc) · 945 Bytes
/
10815.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
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n,m,k;
cin >> n;
long arr_S[n];
for(size_t i=0; i<n; i++){
cin >> arr_S[i];
}
cin >> m;
long arr_C[m];
bool res[m];
for(size_t i=0; i<m; i++){
cin >> arr_C[i];
}
sort(arr_S, arr_S +n);
for(size_t i=0; i<m; i++){ // using binary search
int right = n-1;
int left = 0;
while(left <= right){
int mid = (right+left)/2;
if(arr_S[mid] == arr_C[i]){
res[i]=1;
break;
}
if(arr_S[mid] > arr_C[i]){
right = mid-1;
}
else{
left = mid + 1;
}
}
}
for(size_t i=0; i<m; i++){
if(res[i] == 1) cout << "1" <<" ";
else cout << "0" << " ";
}
}