-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1920.cpp
49 lines (48 loc) · 905 Bytes
/
1920.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
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
int check[100001]; int n, m;
void binary_search(int a) {
int start = 0;
int end = n - 1;
int mid;
while (end - start >= 0) {
mid = (start + end) / 2;
if (check[mid] == a) {
printf("1\n");
return;
}
else if (check[mid] > a) {
end = mid - 1;
}
else {
start = mid + 1;
}
}
printf("0\n");
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int find[100001];
for (int i = 0; i < n; i++) {
cin >> check[i];
}
sort(check, check + n);
cin >> m;
for (int i = 0; i < m; i++) {
cin >> find[i];
binary_search(find[i]);
}
return 0;
}