-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2051C.cpp
More file actions
65 lines (57 loc) · 1.83 KB
/
2051C.cpp
File metadata and controls
65 lines (57 loc) · 1.83 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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
ll n, m, k;
cin >> n >> m >> k;
// Count how many numbers are NOT in array b
int missing_count = n;
vector<bool> present(n + 1, false);
vector<int> a(m);
// Read array a
for(int i = 0; i < m; i++) {
cin >> a[i];
}
// Mark numbers present in array b and count them
for(int i = 0; i < k; i++) {
int x;
cin >> x;
if(!present[x]) {
present[x] = true;
missing_count--;
}
}
string result;
result.reserve(m);
// Key optimization: We know that for result to be '1',
// all numbers except a[i] must be in array b
// This means missing_count must be 0 or 1
if(missing_count > 1) {
// If more than one number is missing, all results must be '0'
result = string(m, '0');
} else {
// If only 0 or 1 numbers are missing
for(int i = 0; i < m; i++) {
// If missing_count is 0, we need all numbers to be in b for '1'
if(missing_count == 0) {
result += '1';
}
// If missing_count is 1, we need the missing number to be a[i] for '1'
else if(missing_count == 1 && !present[a[i]]) {
result += '1';
}
else {
result += '0';
}
}
}
cout << result << '\n';
}
return 0;
}