-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps16.cpp
More file actions
49 lines (36 loc) · 1 KB
/
Copy pathneps16.cpp
File metadata and controls
49 lines (36 loc) · 1 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
/*
* Contest : OBI 2017 - Fase 1
* Problem : Segredo do Cofre
* Link : https://neps.academy/br/exercise/16
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
const int MAX = 10;
int main() {
fastio
int n, m;
cin >> n >> m;
vector<int> v(n + 1, 0), pos(m, 0), ans(MAX, 0);
vector<vector<int>> pref(MAX, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) {
for (int num = 0; num < MAX; num++) pref[num][i] = pref[num][i - 1];
pref[v[i]][i]++;
}
for (int i = 0; i < m; i++) cin >> pos[i];
ans[v[1]]++;
for (int i = 0; i < m - 1; i++) { // O(M-1)
int atual = pos[i], prox = pos[i + 1];
for (int num = 0; num < MAX; num++) {
ans[num] += abs(pref[num][atual] - pref[num][prox]);
if (atual > prox) {
if (v[atual] == num) ans[num]--;
if (v[prox] == num) ans[num]++;
}
}
}
for (auto &i : ans) cout << i << " ";
cout << "\n";
return 0;
}