-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDiscover_the_Monk.cpp
More file actions
70 lines (67 loc) · 1.36 KB
/
Discover_the_Monk.cpp
File metadata and controls
70 lines (67 loc) · 1.36 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
/*
You are given an array A of size N, and Q queries to deal with. For each query, you are given an integer X, and you're supposed to find out if X is present in the array A or not.
Input:
The first line contains two integers, N and Q, denoting the size of array A and number of queries. The second line contains N space separated integers, denoting the array of elements Ai. The next Q lines contain a single integer X per line.
Output:
For each query, print YES if the X is in the array, otherwise print NO.
Constraints:
1 <= N, Q <= 105
1 <= Ai <= 109
1 <= X <= 109
SAMPLE INPUT
5 10
50 40 30 20 10
10
20
30
40
50
60
70
80
90
100
SAMPLE OUTPUT
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
*/
using namespace std;
int main()
{
vector<long long int> vec;
long int n,q;
long long int x;
long long int temp;
cin>>n>>q;
while(n--)
{
cin>>temp;
//using vectors for dynamic array Refer STL in C++
vec.push_back(temp);
}
//since vector is not sorted, sort the vector/array so that we can use binary_search for faster search
sort(vec.begin(), vec.end());
while(q--)
{
cin>>x;
//use binary search
if(std::binary_search(vec.begin(),vec.end(),x))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}