-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfencepainting.cpp
87 lines (71 loc) · 1.58 KB
/
fencepainting.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a;
vector<int> b;
vector<int> c;
int in;
for (int i = 0; i < n; i++) {
cin >> in;
a.emplace_back(in);
}
for (int i = 0; i < n; i++) {
cin >> in;
b.emplace_back(in);
}
for (int i = 0; i < m; i++) {
cin >> in;
c.emplace_back(in);
}
multimap<int, int> inc;
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) inc.emplace(b[i], i);
}
auto last_v = inc.find(c.back());
auto last_resort = find(b.begin(), b.end(), c.back());
int last_i;
if (last_v == inc.end()) {
if (last_resort == b.end()) {
cout << "NO" << endl;
return;
}
else
last_i = last_resort - b.begin();
} else {
inc.erase(last_v);
last_i = last_v->second;
}
vector<int> ans;
for (int i = 0; i < m; i++) {
auto it = inc.find(c[i]);
if (it != inc.end()) {
ans.emplace_back(it->second);
inc.erase(it);
} else
ans.emplace_back(last_i);
}
for (int i = 0; i < m; i++) {
a[ans[i]] = c[i];
}
for (int i = 0; i < n; i++) {
if(a[i] != b[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
for (int i = 0; i < m; i++) {
cout << ans[i] + 1 << " ";
}
cout << endl;
return;
}
int main() {
int t;
cin >> t;
while (t--) solve();
return 0;
}