-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinarySearch.cpp
More file actions
37 lines (36 loc) · 1.03 KB
/
BinarySearch.cpp
File metadata and controls
37 lines (36 loc) · 1.03 KB
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
//Assiut University Training - Newcomers (Z) Binary Search
/*
Given 2 numbers N and Q, array A of N numbers and Q queries each one contains a number X.
For each query print a single line that contains "found" if the number X exists in array A
otherwise, print "not found".
link : https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/Z
*/
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin.exceptions(cin.failbit);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
fast();
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i=0; i<n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
while(q--) {
int x;
cin >> x;
if (binary_search(a.begin(), a.end(), x)) {
cout << "found" << endl;
}
else {
cout << "not found" << endl;
}
}
return (EXIT_SUCCESS);
}