-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path2776.cpp
More file actions
63 lines (59 loc) · 1.26 KB
/
Copy path2776.cpp
File metadata and controls
63 lines (59 loc) · 1.26 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
// Copyright@2023 Jihoon Lucas Kim <jihoon.lucas.kim@gmail.com>
// 암기왕
// https://www.acmicpc.net/problem/2776
// 1. N과 M을 일일이 비교하면 복잡도가 O(NM)이기 때문에 시간 초과가 된다.
// 2. N을 정렬하여 M의 값들을 binary search하여 logN만에 찾도록 하자.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool check(vector<int> &a, int b)
{
int l = 0;
int r = a.size();
while (l <= r)
{
int m = (l + r) / 2;
if (b == a[m])
return true;
else if (b < a[m])
{
r = m - 1;
}
else
{
l = m + 1;
}
}
return false;
}
int main()
{
int T, N, M;
cin >> T;
while (T--)
{
cin >> N;
vector<int> ns(N);
for (int i = 0; i < N; i++)
{
cin >> ns[i];
}
cin >> M;
vector<int> ms(M);
for (int i = 0; i < M; i++)
{
cin >> ms[i];
}
sort(ns.begin(), ns.end());
int p = 0;
for (int i = 0; i < ms.size(); i++)
{
if (check(ns, ms[i]))
cout << "1\n";
else
cout << "0\n";
}
}
return 0;
}