-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarysearch_temp.cpp
More file actions
56 lines (44 loc) · 930 Bytes
/
Copy pathbinarysearch_temp.cpp
File metadata and controls
56 lines (44 loc) · 930 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
52
53
54
55
56
#include <bits/stdc++.h>
#define endl "\n"
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector <ll> vl;
int N, M, target;
int arr[100000];
void solve(){
int start = 0;
int end = N-1;
int mid;
while(start <= end){
mid = (start+end)/2;
if(target == arr[mid]){
cout << "1" << endl;
return;
}
else if( target < arr[mid] ){
end = mid-1;
}
else{
start = mid+1;
}
}
cout << "0" << endl;
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> N;
for(int i=0; i<N; i++) cin >> arr[i];
sort(arr,arr+N);
cin >> M;
while(M--){
cin >> target;
solve();
}
}