#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
const int N = 1000005;
int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
if (m == 1) {
cout << "0\n"; return 0;
}
for (int i = 1; i <= n; ++i) {
cin >> a[i], cnt[a[i]]++, p[a[i]].push_back(i);
}
set<ii> s;
for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
for (int i = 1; i <= m; ++i) {
res[i] = 1e9;
for (int j = 0; j < 2; ++j) {
vector<int> go;
int sum = 0;
for (int k = 0; k < p[i].size(); ++k) {
if (p[i][k] % 2 == j) {
int cur = a[p[i][k] - 1];
if (p[i][k] > 1 && cur != i) {
if (++val[cur] == 1) go.push_back(cur);
}
}
else {
int cur = a[p[i][k] + 1];
if (p[i][k] < n && cur != i) {
if (++val[cur] == 1) go.push_back(cur);
}
}
}
for (int k = 0; k < go.size(); ++k) {
s.erase(s.find(ii(cnt[go[k]], go[k])));
s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
}
s.erase(s.find(ii(cnt[i], i)));
res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
for (int k = 0; k < go.size(); ++k) {
s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
s.insert(ii(cnt[go[k]], go[k]));
}
s.insert(ii(cnt[i], i));
for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
}
cout << res[i] << '\n';
}
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < p[i].size(); ++k) {
^
rope.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) {
^
rope.cpp:48:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) {
^
rope.cpp:53:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
^
rope.cpp:27:8: warning: unused variable 'sum' [-Wunused-variable]
int sum = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41240 KB |
Output is correct |
2 |
Correct |
6 ms |
41240 KB |
Output is correct |
3 |
Correct |
9 ms |
41240 KB |
Output is correct |
4 |
Correct |
3 ms |
41240 KB |
Output is correct |
5 |
Correct |
6 ms |
41240 KB |
Output is correct |
6 |
Correct |
3 ms |
41240 KB |
Output is correct |
7 |
Correct |
9 ms |
41240 KB |
Output is correct |
8 |
Correct |
3 ms |
41240 KB |
Output is correct |
9 |
Correct |
6 ms |
41240 KB |
Output is correct |
10 |
Correct |
3 ms |
41240 KB |
Output is correct |
11 |
Correct |
6 ms |
41240 KB |
Output is correct |
12 |
Correct |
3 ms |
41240 KB |
Output is correct |
13 |
Correct |
0 ms |
41240 KB |
Output is correct |
14 |
Correct |
0 ms |
41240 KB |
Output is correct |
15 |
Correct |
13 ms |
41240 KB |
Output is correct |
16 |
Correct |
3 ms |
41240 KB |
Output is correct |
17 |
Correct |
6 ms |
41240 KB |
Output is correct |
18 |
Correct |
6 ms |
41240 KB |
Output is correct |
19 |
Correct |
3 ms |
41240 KB |
Output is correct |
20 |
Correct |
3 ms |
41240 KB |
Output is correct |
21 |
Correct |
6 ms |
41240 KB |
Output is correct |
22 |
Correct |
3 ms |
41240 KB |
Output is correct |
23 |
Correct |
13 ms |
41240 KB |
Output is correct |
24 |
Correct |
9 ms |
41240 KB |
Output is correct |
25 |
Correct |
6 ms |
41240 KB |
Output is correct |
26 |
Correct |
3 ms |
41240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41240 KB |
Output is correct |
2 |
Correct |
6 ms |
41240 KB |
Output is correct |
3 |
Correct |
9 ms |
41240 KB |
Output is correct |
4 |
Correct |
3 ms |
41240 KB |
Output is correct |
5 |
Correct |
6 ms |
41240 KB |
Output is correct |
6 |
Correct |
3 ms |
41240 KB |
Output is correct |
7 |
Correct |
9 ms |
41240 KB |
Output is correct |
8 |
Correct |
3 ms |
41240 KB |
Output is correct |
9 |
Correct |
6 ms |
41240 KB |
Output is correct |
10 |
Correct |
3 ms |
41240 KB |
Output is correct |
11 |
Correct |
6 ms |
41240 KB |
Output is correct |
12 |
Correct |
3 ms |
41240 KB |
Output is correct |
13 |
Correct |
0 ms |
41240 KB |
Output is correct |
14 |
Correct |
0 ms |
41240 KB |
Output is correct |
15 |
Correct |
13 ms |
41240 KB |
Output is correct |
16 |
Correct |
3 ms |
41240 KB |
Output is correct |
17 |
Correct |
6 ms |
41240 KB |
Output is correct |
18 |
Correct |
6 ms |
41240 KB |
Output is correct |
19 |
Correct |
3 ms |
41240 KB |
Output is correct |
20 |
Correct |
3 ms |
41240 KB |
Output is correct |
21 |
Correct |
6 ms |
41240 KB |
Output is correct |
22 |
Correct |
3 ms |
41240 KB |
Output is correct |
23 |
Correct |
13 ms |
41240 KB |
Output is correct |
24 |
Correct |
9 ms |
41240 KB |
Output is correct |
25 |
Correct |
6 ms |
41240 KB |
Output is correct |
26 |
Correct |
3 ms |
41240 KB |
Output is correct |
27 |
Correct |
13 ms |
42072 KB |
Output is correct |
28 |
Correct |
9 ms |
41816 KB |
Output is correct |
29 |
Correct |
29 ms |
41892 KB |
Output is correct |
30 |
Correct |
9 ms |
41988 KB |
Output is correct |
31 |
Correct |
13 ms |
41912 KB |
Output is correct |
32 |
Correct |
13 ms |
41836 KB |
Output is correct |
33 |
Correct |
19 ms |
41868 KB |
Output is correct |
34 |
Correct |
13 ms |
41856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41240 KB |
Output is correct |
2 |
Correct |
6 ms |
41240 KB |
Output is correct |
3 |
Correct |
9 ms |
41240 KB |
Output is correct |
4 |
Correct |
3 ms |
41240 KB |
Output is correct |
5 |
Correct |
6 ms |
41240 KB |
Output is correct |
6 |
Correct |
3 ms |
41240 KB |
Output is correct |
7 |
Correct |
9 ms |
41240 KB |
Output is correct |
8 |
Correct |
3 ms |
41240 KB |
Output is correct |
9 |
Correct |
6 ms |
41240 KB |
Output is correct |
10 |
Correct |
3 ms |
41240 KB |
Output is correct |
11 |
Correct |
6 ms |
41240 KB |
Output is correct |
12 |
Correct |
3 ms |
41240 KB |
Output is correct |
13 |
Correct |
0 ms |
41240 KB |
Output is correct |
14 |
Correct |
0 ms |
41240 KB |
Output is correct |
15 |
Correct |
13 ms |
41240 KB |
Output is correct |
16 |
Correct |
3 ms |
41240 KB |
Output is correct |
17 |
Correct |
6 ms |
41240 KB |
Output is correct |
18 |
Correct |
6 ms |
41240 KB |
Output is correct |
19 |
Correct |
3 ms |
41240 KB |
Output is correct |
20 |
Correct |
3 ms |
41240 KB |
Output is correct |
21 |
Correct |
6 ms |
41240 KB |
Output is correct |
22 |
Correct |
3 ms |
41240 KB |
Output is correct |
23 |
Correct |
13 ms |
41240 KB |
Output is correct |
24 |
Correct |
9 ms |
41240 KB |
Output is correct |
25 |
Correct |
6 ms |
41240 KB |
Output is correct |
26 |
Correct |
3 ms |
41240 KB |
Output is correct |
27 |
Correct |
13 ms |
42072 KB |
Output is correct |
28 |
Correct |
9 ms |
41816 KB |
Output is correct |
29 |
Correct |
29 ms |
41892 KB |
Output is correct |
30 |
Correct |
9 ms |
41988 KB |
Output is correct |
31 |
Correct |
13 ms |
41912 KB |
Output is correct |
32 |
Correct |
13 ms |
41836 KB |
Output is correct |
33 |
Correct |
19 ms |
41868 KB |
Output is correct |
34 |
Correct |
13 ms |
41856 KB |
Output is correct |
35 |
Correct |
126 ms |
41768 KB |
Output is correct |
36 |
Correct |
123 ms |
41768 KB |
Output is correct |
37 |
Correct |
126 ms |
41768 KB |
Output is correct |
38 |
Correct |
116 ms |
41768 KB |
Output is correct |
39 |
Correct |
113 ms |
41768 KB |
Output is correct |
40 |
Correct |
63 ms |
41900 KB |
Output is correct |
41 |
Correct |
73 ms |
41900 KB |
Output is correct |
42 |
Correct |
63 ms |
41768 KB |
Output is correct |
43 |
Correct |
53 ms |
41900 KB |
Output is correct |
44 |
Correct |
73 ms |
41900 KB |
Output is correct |
45 |
Correct |
63 ms |
41900 KB |
Output is correct |
46 |
Correct |
49 ms |
41768 KB |
Output is correct |
47 |
Correct |
66 ms |
41900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41240 KB |
Output is correct |
2 |
Correct |
6 ms |
41240 KB |
Output is correct |
3 |
Correct |
9 ms |
41240 KB |
Output is correct |
4 |
Correct |
3 ms |
41240 KB |
Output is correct |
5 |
Correct |
6 ms |
41240 KB |
Output is correct |
6 |
Correct |
3 ms |
41240 KB |
Output is correct |
7 |
Correct |
9 ms |
41240 KB |
Output is correct |
8 |
Correct |
3 ms |
41240 KB |
Output is correct |
9 |
Correct |
6 ms |
41240 KB |
Output is correct |
10 |
Correct |
3 ms |
41240 KB |
Output is correct |
11 |
Correct |
6 ms |
41240 KB |
Output is correct |
12 |
Correct |
3 ms |
41240 KB |
Output is correct |
13 |
Correct |
0 ms |
41240 KB |
Output is correct |
14 |
Correct |
0 ms |
41240 KB |
Output is correct |
15 |
Correct |
13 ms |
41240 KB |
Output is correct |
16 |
Correct |
3 ms |
41240 KB |
Output is correct |
17 |
Correct |
6 ms |
41240 KB |
Output is correct |
18 |
Correct |
6 ms |
41240 KB |
Output is correct |
19 |
Correct |
3 ms |
41240 KB |
Output is correct |
20 |
Correct |
3 ms |
41240 KB |
Output is correct |
21 |
Correct |
6 ms |
41240 KB |
Output is correct |
22 |
Correct |
3 ms |
41240 KB |
Output is correct |
23 |
Correct |
13 ms |
41240 KB |
Output is correct |
24 |
Correct |
9 ms |
41240 KB |
Output is correct |
25 |
Correct |
6 ms |
41240 KB |
Output is correct |
26 |
Correct |
3 ms |
41240 KB |
Output is correct |
27 |
Correct |
13 ms |
42072 KB |
Output is correct |
28 |
Correct |
9 ms |
41816 KB |
Output is correct |
29 |
Correct |
29 ms |
41892 KB |
Output is correct |
30 |
Correct |
9 ms |
41988 KB |
Output is correct |
31 |
Correct |
13 ms |
41912 KB |
Output is correct |
32 |
Correct |
13 ms |
41836 KB |
Output is correct |
33 |
Correct |
19 ms |
41868 KB |
Output is correct |
34 |
Correct |
13 ms |
41856 KB |
Output is correct |
35 |
Correct |
126 ms |
41768 KB |
Output is correct |
36 |
Correct |
123 ms |
41768 KB |
Output is correct |
37 |
Correct |
126 ms |
41768 KB |
Output is correct |
38 |
Correct |
116 ms |
41768 KB |
Output is correct |
39 |
Correct |
113 ms |
41768 KB |
Output is correct |
40 |
Correct |
63 ms |
41900 KB |
Output is correct |
41 |
Correct |
73 ms |
41900 KB |
Output is correct |
42 |
Correct |
63 ms |
41768 KB |
Output is correct |
43 |
Correct |
53 ms |
41900 KB |
Output is correct |
44 |
Correct |
73 ms |
41900 KB |
Output is correct |
45 |
Correct |
63 ms |
41900 KB |
Output is correct |
46 |
Correct |
49 ms |
41768 KB |
Output is correct |
47 |
Correct |
66 ms |
41900 KB |
Output is correct |
48 |
Runtime error |
813 ms |
47840 KB |
Execution killed because of forbidden syscall writev (20) |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41240 KB |
Output is correct |
2 |
Correct |
6 ms |
41240 KB |
Output is correct |
3 |
Correct |
9 ms |
41240 KB |
Output is correct |
4 |
Correct |
3 ms |
41240 KB |
Output is correct |
5 |
Correct |
6 ms |
41240 KB |
Output is correct |
6 |
Correct |
3 ms |
41240 KB |
Output is correct |
7 |
Correct |
9 ms |
41240 KB |
Output is correct |
8 |
Correct |
3 ms |
41240 KB |
Output is correct |
9 |
Correct |
6 ms |
41240 KB |
Output is correct |
10 |
Correct |
3 ms |
41240 KB |
Output is correct |
11 |
Correct |
6 ms |
41240 KB |
Output is correct |
12 |
Correct |
3 ms |
41240 KB |
Output is correct |
13 |
Correct |
0 ms |
41240 KB |
Output is correct |
14 |
Correct |
0 ms |
41240 KB |
Output is correct |
15 |
Correct |
13 ms |
41240 KB |
Output is correct |
16 |
Correct |
3 ms |
41240 KB |
Output is correct |
17 |
Correct |
6 ms |
41240 KB |
Output is correct |
18 |
Correct |
6 ms |
41240 KB |
Output is correct |
19 |
Correct |
3 ms |
41240 KB |
Output is correct |
20 |
Correct |
3 ms |
41240 KB |
Output is correct |
21 |
Correct |
6 ms |
41240 KB |
Output is correct |
22 |
Correct |
3 ms |
41240 KB |
Output is correct |
23 |
Correct |
13 ms |
41240 KB |
Output is correct |
24 |
Correct |
9 ms |
41240 KB |
Output is correct |
25 |
Correct |
6 ms |
41240 KB |
Output is correct |
26 |
Correct |
3 ms |
41240 KB |
Output is correct |
27 |
Correct |
13 ms |
42072 KB |
Output is correct |
28 |
Correct |
9 ms |
41816 KB |
Output is correct |
29 |
Correct |
29 ms |
41892 KB |
Output is correct |
30 |
Correct |
9 ms |
41988 KB |
Output is correct |
31 |
Correct |
13 ms |
41912 KB |
Output is correct |
32 |
Correct |
13 ms |
41836 KB |
Output is correct |
33 |
Correct |
19 ms |
41868 KB |
Output is correct |
34 |
Correct |
13 ms |
41856 KB |
Output is correct |
35 |
Correct |
126 ms |
41768 KB |
Output is correct |
36 |
Correct |
123 ms |
41768 KB |
Output is correct |
37 |
Correct |
126 ms |
41768 KB |
Output is correct |
38 |
Correct |
116 ms |
41768 KB |
Output is correct |
39 |
Correct |
113 ms |
41768 KB |
Output is correct |
40 |
Correct |
63 ms |
41900 KB |
Output is correct |
41 |
Correct |
73 ms |
41900 KB |
Output is correct |
42 |
Correct |
63 ms |
41768 KB |
Output is correct |
43 |
Correct |
53 ms |
41900 KB |
Output is correct |
44 |
Correct |
73 ms |
41900 KB |
Output is correct |
45 |
Correct |
63 ms |
41900 KB |
Output is correct |
46 |
Correct |
49 ms |
41768 KB |
Output is correct |
47 |
Correct |
66 ms |
41900 KB |
Output is correct |
48 |
Runtime error |
813 ms |
47840 KB |
Execution killed because of forbidden syscall writev (20) |
49 |
Halted |
0 ms |
0 KB |
- |