-
Notifications
You must be signed in to change notification settings - Fork 0
/
monk and his friend.txt
70 lines (55 loc) · 1.53 KB
/
monk and his friend.txt
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
Monk is standing at the door of his classroom. There are currently N students in the class, i'th student got Ai candies.
There are still M more students to come. At every instant, a student enters the class and wishes to be seated with a student who has exactly the same number of candies. For each student, Monk shouts YES if such a student is found, NO otherwise.
Input:
First line contains an integer T. T test cases follow.
First line of each case contains two space-separated integers N and M.
Second line contains N + M space-separated integers, the candies of the students.
Output:
For each test case, output M new line, Monk's answer to the M students.
Print "YES" (without the quotes) or "NO" (without the quotes) pertaining to the Monk's answer.
Constraints:
1 ≤ T ≤ 10
1 ≤ N, M ≤ 105
0 ≤ Ai ≤ 1012
Sample Input
1
2 3
3 2 9 11 2
Sample Output
NO
NO
YES
\
solution
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
unordered_set<long long> s;
for(int i = 0 ; i < n ; i++)
{
long long x;
cin >> x;
s.insert(x);
}
for(int i = 0 ; i < m; i++)
{
long long val;
cin >> val;
auto it = s.find(val);
if (it != s.end())
cout << "YES" << endl;
else
cout << "NO" << endl;
s.insert(val);
}
}
}