#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
const int MAXN = 1000055;
int D[MAXN][2];
bitset<MAXN> chk;
vector<int> G[MAXN];
int O[MAXN];
int A[MAXN], B[MAXN];
int N, M;
int main() {
ios::sync_with_stdio(false);
cin >> N >> M;
for(int i = 1; i <= N; i++) {
cin >> A[i];
B[A[i]]++;
}
for(int i = 1; i <= M; i++) G[B[i]].eb(i);
for(int i = N, c = 0; i; i--)
for(int v : G[i]) O[++c] = v;
for(int i = 0; i <= N; i++) G[i].clear();
for(int i = 1; i < N; i++) if(A[i] != A[i+1]) {
G[A[i]].eb(i+1);
G[A[i+1]].eb(-i);
}
for(int i = 1; i <= M; i++) {
int ret = 0, dg = 0;
for(int v : G[i]) {
D[A[abs(v)]][(0 < v ? v-1 : -v)&1]++;
chk[A[abs(v)]] = true;
dg++;
}
for(int oi = 1, c; oi <= M && oi <= dg+2; oi++) {
c = O[oi];
if(c == i || chk[c]) continue;
ret = -B[c];
break;
}
for(int v : G[i]) {
int c = A[abs(v)], t = min(D[c][0], D[c][1]) - B[c];
if(t < ret) ret = t;
}
for(int v : G[i]) {
D[A[abs(v)]][(0 < v ? v-1 : -v)&1] = 0;
chk[A[abs(v)]] = false;
}
printf("%d\n", ret + N-B[i]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23844 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
29 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23800 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
24 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
26 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
23800 KB |
Output is correct |
19 |
Correct |
23 ms |
23804 KB |
Output is correct |
20 |
Correct |
24 ms |
23928 KB |
Output is correct |
21 |
Correct |
23 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23844 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
29 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23800 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
24 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
26 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
23800 KB |
Output is correct |
19 |
Correct |
23 ms |
23804 KB |
Output is correct |
20 |
Correct |
24 ms |
23928 KB |
Output is correct |
21 |
Correct |
23 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
38 ms |
25580 KB |
Output is correct |
28 |
Correct |
37 ms |
25328 KB |
Output is correct |
29 |
Correct |
38 ms |
25592 KB |
Output is correct |
30 |
Correct |
37 ms |
25176 KB |
Output is correct |
31 |
Correct |
38 ms |
25720 KB |
Output is correct |
32 |
Correct |
37 ms |
25208 KB |
Output is correct |
33 |
Correct |
38 ms |
25592 KB |
Output is correct |
34 |
Correct |
37 ms |
25292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23844 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
29 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23800 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
24 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
26 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
23800 KB |
Output is correct |
19 |
Correct |
23 ms |
23804 KB |
Output is correct |
20 |
Correct |
24 ms |
23928 KB |
Output is correct |
21 |
Correct |
23 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
38 ms |
25580 KB |
Output is correct |
28 |
Correct |
37 ms |
25328 KB |
Output is correct |
29 |
Correct |
38 ms |
25592 KB |
Output is correct |
30 |
Correct |
37 ms |
25176 KB |
Output is correct |
31 |
Correct |
38 ms |
25720 KB |
Output is correct |
32 |
Correct |
37 ms |
25208 KB |
Output is correct |
33 |
Correct |
38 ms |
25592 KB |
Output is correct |
34 |
Correct |
37 ms |
25292 KB |
Output is correct |
35 |
Correct |
42 ms |
25812 KB |
Output is correct |
36 |
Correct |
42 ms |
25680 KB |
Output is correct |
37 |
Correct |
42 ms |
25712 KB |
Output is correct |
38 |
Correct |
42 ms |
25720 KB |
Output is correct |
39 |
Correct |
43 ms |
25720 KB |
Output is correct |
40 |
Correct |
47 ms |
25848 KB |
Output is correct |
41 |
Correct |
41 ms |
25848 KB |
Output is correct |
42 |
Correct |
42 ms |
25820 KB |
Output is correct |
43 |
Correct |
42 ms |
25976 KB |
Output is correct |
44 |
Correct |
41 ms |
25852 KB |
Output is correct |
45 |
Correct |
42 ms |
25848 KB |
Output is correct |
46 |
Correct |
43 ms |
25940 KB |
Output is correct |
47 |
Correct |
48 ms |
25848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23844 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
29 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23800 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
24 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
26 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
23800 KB |
Output is correct |
19 |
Correct |
23 ms |
23804 KB |
Output is correct |
20 |
Correct |
24 ms |
23928 KB |
Output is correct |
21 |
Correct |
23 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
38 ms |
25580 KB |
Output is correct |
28 |
Correct |
37 ms |
25328 KB |
Output is correct |
29 |
Correct |
38 ms |
25592 KB |
Output is correct |
30 |
Correct |
37 ms |
25176 KB |
Output is correct |
31 |
Correct |
38 ms |
25720 KB |
Output is correct |
32 |
Correct |
37 ms |
25208 KB |
Output is correct |
33 |
Correct |
38 ms |
25592 KB |
Output is correct |
34 |
Correct |
37 ms |
25292 KB |
Output is correct |
35 |
Correct |
42 ms |
25812 KB |
Output is correct |
36 |
Correct |
42 ms |
25680 KB |
Output is correct |
37 |
Correct |
42 ms |
25712 KB |
Output is correct |
38 |
Correct |
42 ms |
25720 KB |
Output is correct |
39 |
Correct |
43 ms |
25720 KB |
Output is correct |
40 |
Correct |
47 ms |
25848 KB |
Output is correct |
41 |
Correct |
41 ms |
25848 KB |
Output is correct |
42 |
Correct |
42 ms |
25820 KB |
Output is correct |
43 |
Correct |
42 ms |
25976 KB |
Output is correct |
44 |
Correct |
41 ms |
25852 KB |
Output is correct |
45 |
Correct |
42 ms |
25848 KB |
Output is correct |
46 |
Correct |
43 ms |
25940 KB |
Output is correct |
47 |
Correct |
48 ms |
25848 KB |
Output is correct |
48 |
Correct |
304 ms |
45604 KB |
Output is correct |
49 |
Correct |
286 ms |
45620 KB |
Output is correct |
50 |
Correct |
259 ms |
45688 KB |
Output is correct |
51 |
Correct |
242 ms |
45204 KB |
Output is correct |
52 |
Correct |
233 ms |
42124 KB |
Output is correct |
53 |
Correct |
236 ms |
44156 KB |
Output is correct |
54 |
Correct |
227 ms |
41996 KB |
Output is correct |
55 |
Correct |
243 ms |
41664 KB |
Output is correct |
56 |
Correct |
237 ms |
41252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23844 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
29 ms |
23800 KB |
Output is correct |
7 |
Correct |
23 ms |
23800 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23800 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
24 ms |
23800 KB |
Output is correct |
12 |
Correct |
23 ms |
23800 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
24 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
26 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
23800 KB |
Output is correct |
19 |
Correct |
23 ms |
23804 KB |
Output is correct |
20 |
Correct |
24 ms |
23928 KB |
Output is correct |
21 |
Correct |
23 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
24 ms |
23800 KB |
Output is correct |
27 |
Correct |
38 ms |
25580 KB |
Output is correct |
28 |
Correct |
37 ms |
25328 KB |
Output is correct |
29 |
Correct |
38 ms |
25592 KB |
Output is correct |
30 |
Correct |
37 ms |
25176 KB |
Output is correct |
31 |
Correct |
38 ms |
25720 KB |
Output is correct |
32 |
Correct |
37 ms |
25208 KB |
Output is correct |
33 |
Correct |
38 ms |
25592 KB |
Output is correct |
34 |
Correct |
37 ms |
25292 KB |
Output is correct |
35 |
Correct |
42 ms |
25812 KB |
Output is correct |
36 |
Correct |
42 ms |
25680 KB |
Output is correct |
37 |
Correct |
42 ms |
25712 KB |
Output is correct |
38 |
Correct |
42 ms |
25720 KB |
Output is correct |
39 |
Correct |
43 ms |
25720 KB |
Output is correct |
40 |
Correct |
47 ms |
25848 KB |
Output is correct |
41 |
Correct |
41 ms |
25848 KB |
Output is correct |
42 |
Correct |
42 ms |
25820 KB |
Output is correct |
43 |
Correct |
42 ms |
25976 KB |
Output is correct |
44 |
Correct |
41 ms |
25852 KB |
Output is correct |
45 |
Correct |
42 ms |
25848 KB |
Output is correct |
46 |
Correct |
43 ms |
25940 KB |
Output is correct |
47 |
Correct |
48 ms |
25848 KB |
Output is correct |
48 |
Correct |
304 ms |
45604 KB |
Output is correct |
49 |
Correct |
286 ms |
45620 KB |
Output is correct |
50 |
Correct |
259 ms |
45688 KB |
Output is correct |
51 |
Correct |
242 ms |
45204 KB |
Output is correct |
52 |
Correct |
233 ms |
42124 KB |
Output is correct |
53 |
Correct |
236 ms |
44156 KB |
Output is correct |
54 |
Correct |
227 ms |
41996 KB |
Output is correct |
55 |
Correct |
243 ms |
41664 KB |
Output is correct |
56 |
Correct |
237 ms |
41252 KB |
Output is correct |
57 |
Correct |
1212 ms |
92108 KB |
Output is correct |
58 |
Correct |
956 ms |
70984 KB |
Output is correct |
59 |
Correct |
973 ms |
70952 KB |
Output is correct |
60 |
Correct |
1109 ms |
76028 KB |
Output is correct |
61 |
Correct |
1058 ms |
76232 KB |
Output is correct |
62 |
Correct |
488 ms |
58028 KB |
Output is correct |
63 |
Correct |
716 ms |
64360 KB |
Output is correct |
64 |
Correct |
581 ms |
60524 KB |
Output is correct |
65 |
Correct |
359 ms |
50384 KB |
Output is correct |