#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX=1000010, inf=2e9;
int n, m, A[MX];
int C[2][MX];
int ans[MX];
int idx[2][MX];
vector<int> G[2][MX];
void init(){
fill(ans+1, ans+m+1, inf);
for(int i=0; i<=n; i++){
C[i%2][A[i]]++; C[i%2][A[i+1]]++;
}
for(int i=1; i<n; i++){
if(A[i]==A[i+1]) continue;
G[i%2][A[i]].push_back(A[i+1]);
G[i%2][A[i+1]].push_back(A[i]);
}
iota(idx[0]+1, idx[0]+m+1, 1);
iota(idx[1]+1, idx[1]+m+1, 1);
sort(idx[0]+1, idx[0]+m+1, [](int a, int b){ return C[0][a]>C[0][b]; });
sort(idx[1]+1, idx[1]+m+1, [](int a, int b){ return C[1][a]>C[1][b]; });
}
void solve(){
int adj[MX]={};
for(int v=1; v<=m; v++){
for(int k=0; k<=1; k++){
int mx=0;
for(int x:G[k][v]) adj[x]++;
for(int x:G[k][v]){
mx=max(mx, C[k][x]-adj[x]);
}
for(int i=1; i<=m; i++){
int x=idx[k][i];
if(x!=v && adj[x]==0){
mx=max(mx, C[k][x]);
break;
}
}
for(int x:G[k][v]) adj[x]--;
ans[v]=min(ans[v], n-C[k][v]-mx);
}
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>A[i];
init();
solve();
for(int i=1; i<=m; i++) cout<<ans[i]<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
51192 KB |
Output is correct |
2 |
Correct |
43 ms |
51304 KB |
Output is correct |
3 |
Correct |
42 ms |
51416 KB |
Output is correct |
4 |
Correct |
50 ms |
51552 KB |
Output is correct |
5 |
Correct |
43 ms |
51552 KB |
Output is correct |
6 |
Correct |
43 ms |
51560 KB |
Output is correct |
7 |
Correct |
45 ms |
51576 KB |
Output is correct |
8 |
Correct |
46 ms |
51676 KB |
Output is correct |
9 |
Correct |
43 ms |
51676 KB |
Output is correct |
10 |
Correct |
46 ms |
51676 KB |
Output is correct |
11 |
Correct |
43 ms |
51676 KB |
Output is correct |
12 |
Correct |
46 ms |
51704 KB |
Output is correct |
13 |
Correct |
45 ms |
51704 KB |
Output is correct |
14 |
Correct |
44 ms |
51704 KB |
Output is correct |
15 |
Correct |
47 ms |
51704 KB |
Output is correct |
16 |
Correct |
45 ms |
51704 KB |
Output is correct |
17 |
Correct |
48 ms |
51704 KB |
Output is correct |
18 |
Correct |
47 ms |
51704 KB |
Output is correct |
19 |
Correct |
42 ms |
51704 KB |
Output is correct |
20 |
Correct |
42 ms |
51704 KB |
Output is correct |
21 |
Correct |
45 ms |
51712 KB |
Output is correct |
22 |
Correct |
44 ms |
51744 KB |
Output is correct |
23 |
Correct |
50 ms |
51744 KB |
Output is correct |
24 |
Correct |
45 ms |
51744 KB |
Output is correct |
25 |
Correct |
51 ms |
51744 KB |
Output is correct |
26 |
Correct |
51 ms |
51764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
51192 KB |
Output is correct |
2 |
Correct |
43 ms |
51304 KB |
Output is correct |
3 |
Correct |
42 ms |
51416 KB |
Output is correct |
4 |
Correct |
50 ms |
51552 KB |
Output is correct |
5 |
Correct |
43 ms |
51552 KB |
Output is correct |
6 |
Correct |
43 ms |
51560 KB |
Output is correct |
7 |
Correct |
45 ms |
51576 KB |
Output is correct |
8 |
Correct |
46 ms |
51676 KB |
Output is correct |
9 |
Correct |
43 ms |
51676 KB |
Output is correct |
10 |
Correct |
46 ms |
51676 KB |
Output is correct |
11 |
Correct |
43 ms |
51676 KB |
Output is correct |
12 |
Correct |
46 ms |
51704 KB |
Output is correct |
13 |
Correct |
45 ms |
51704 KB |
Output is correct |
14 |
Correct |
44 ms |
51704 KB |
Output is correct |
15 |
Correct |
47 ms |
51704 KB |
Output is correct |
16 |
Correct |
45 ms |
51704 KB |
Output is correct |
17 |
Correct |
48 ms |
51704 KB |
Output is correct |
18 |
Correct |
47 ms |
51704 KB |
Output is correct |
19 |
Correct |
42 ms |
51704 KB |
Output is correct |
20 |
Correct |
42 ms |
51704 KB |
Output is correct |
21 |
Correct |
45 ms |
51712 KB |
Output is correct |
22 |
Correct |
44 ms |
51744 KB |
Output is correct |
23 |
Correct |
50 ms |
51744 KB |
Output is correct |
24 |
Correct |
45 ms |
51744 KB |
Output is correct |
25 |
Correct |
51 ms |
51744 KB |
Output is correct |
26 |
Correct |
51 ms |
51764 KB |
Output is correct |
27 |
Correct |
53 ms |
53444 KB |
Output is correct |
28 |
Correct |
52 ms |
53528 KB |
Output is correct |
29 |
Correct |
52 ms |
53868 KB |
Output is correct |
30 |
Correct |
52 ms |
53868 KB |
Output is correct |
31 |
Correct |
52 ms |
54404 KB |
Output is correct |
32 |
Correct |
53 ms |
54404 KB |
Output is correct |
33 |
Correct |
53 ms |
54696 KB |
Output is correct |
34 |
Correct |
52 ms |
54696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
51192 KB |
Output is correct |
2 |
Correct |
43 ms |
51304 KB |
Output is correct |
3 |
Correct |
42 ms |
51416 KB |
Output is correct |
4 |
Correct |
50 ms |
51552 KB |
Output is correct |
5 |
Correct |
43 ms |
51552 KB |
Output is correct |
6 |
Correct |
43 ms |
51560 KB |
Output is correct |
7 |
Correct |
45 ms |
51576 KB |
Output is correct |
8 |
Correct |
46 ms |
51676 KB |
Output is correct |
9 |
Correct |
43 ms |
51676 KB |
Output is correct |
10 |
Correct |
46 ms |
51676 KB |
Output is correct |
11 |
Correct |
43 ms |
51676 KB |
Output is correct |
12 |
Correct |
46 ms |
51704 KB |
Output is correct |
13 |
Correct |
45 ms |
51704 KB |
Output is correct |
14 |
Correct |
44 ms |
51704 KB |
Output is correct |
15 |
Correct |
47 ms |
51704 KB |
Output is correct |
16 |
Correct |
45 ms |
51704 KB |
Output is correct |
17 |
Correct |
48 ms |
51704 KB |
Output is correct |
18 |
Correct |
47 ms |
51704 KB |
Output is correct |
19 |
Correct |
42 ms |
51704 KB |
Output is correct |
20 |
Correct |
42 ms |
51704 KB |
Output is correct |
21 |
Correct |
45 ms |
51712 KB |
Output is correct |
22 |
Correct |
44 ms |
51744 KB |
Output is correct |
23 |
Correct |
50 ms |
51744 KB |
Output is correct |
24 |
Correct |
45 ms |
51744 KB |
Output is correct |
25 |
Correct |
51 ms |
51744 KB |
Output is correct |
26 |
Correct |
51 ms |
51764 KB |
Output is correct |
27 |
Correct |
53 ms |
53444 KB |
Output is correct |
28 |
Correct |
52 ms |
53528 KB |
Output is correct |
29 |
Correct |
52 ms |
53868 KB |
Output is correct |
30 |
Correct |
52 ms |
53868 KB |
Output is correct |
31 |
Correct |
52 ms |
54404 KB |
Output is correct |
32 |
Correct |
53 ms |
54404 KB |
Output is correct |
33 |
Correct |
53 ms |
54696 KB |
Output is correct |
34 |
Correct |
52 ms |
54696 KB |
Output is correct |
35 |
Correct |
61 ms |
55232 KB |
Output is correct |
36 |
Correct |
62 ms |
55604 KB |
Output is correct |
37 |
Correct |
59 ms |
56020 KB |
Output is correct |
38 |
Correct |
58 ms |
56364 KB |
Output is correct |
39 |
Correct |
60 ms |
56720 KB |
Output is correct |
40 |
Correct |
56 ms |
57220 KB |
Output is correct |
41 |
Correct |
54 ms |
57720 KB |
Output is correct |
42 |
Correct |
55 ms |
57964 KB |
Output is correct |
43 |
Correct |
55 ms |
58376 KB |
Output is correct |
44 |
Correct |
57 ms |
58684 KB |
Output is correct |
45 |
Correct |
56 ms |
59208 KB |
Output is correct |
46 |
Correct |
61 ms |
59404 KB |
Output is correct |
47 |
Correct |
57 ms |
59848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
51192 KB |
Output is correct |
2 |
Correct |
43 ms |
51304 KB |
Output is correct |
3 |
Correct |
42 ms |
51416 KB |
Output is correct |
4 |
Correct |
50 ms |
51552 KB |
Output is correct |
5 |
Correct |
43 ms |
51552 KB |
Output is correct |
6 |
Correct |
43 ms |
51560 KB |
Output is correct |
7 |
Correct |
45 ms |
51576 KB |
Output is correct |
8 |
Correct |
46 ms |
51676 KB |
Output is correct |
9 |
Correct |
43 ms |
51676 KB |
Output is correct |
10 |
Correct |
46 ms |
51676 KB |
Output is correct |
11 |
Correct |
43 ms |
51676 KB |
Output is correct |
12 |
Correct |
46 ms |
51704 KB |
Output is correct |
13 |
Correct |
45 ms |
51704 KB |
Output is correct |
14 |
Correct |
44 ms |
51704 KB |
Output is correct |
15 |
Correct |
47 ms |
51704 KB |
Output is correct |
16 |
Correct |
45 ms |
51704 KB |
Output is correct |
17 |
Correct |
48 ms |
51704 KB |
Output is correct |
18 |
Correct |
47 ms |
51704 KB |
Output is correct |
19 |
Correct |
42 ms |
51704 KB |
Output is correct |
20 |
Correct |
42 ms |
51704 KB |
Output is correct |
21 |
Correct |
45 ms |
51712 KB |
Output is correct |
22 |
Correct |
44 ms |
51744 KB |
Output is correct |
23 |
Correct |
50 ms |
51744 KB |
Output is correct |
24 |
Correct |
45 ms |
51744 KB |
Output is correct |
25 |
Correct |
51 ms |
51744 KB |
Output is correct |
26 |
Correct |
51 ms |
51764 KB |
Output is correct |
27 |
Correct |
53 ms |
53444 KB |
Output is correct |
28 |
Correct |
52 ms |
53528 KB |
Output is correct |
29 |
Correct |
52 ms |
53868 KB |
Output is correct |
30 |
Correct |
52 ms |
53868 KB |
Output is correct |
31 |
Correct |
52 ms |
54404 KB |
Output is correct |
32 |
Correct |
53 ms |
54404 KB |
Output is correct |
33 |
Correct |
53 ms |
54696 KB |
Output is correct |
34 |
Correct |
52 ms |
54696 KB |
Output is correct |
35 |
Correct |
61 ms |
55232 KB |
Output is correct |
36 |
Correct |
62 ms |
55604 KB |
Output is correct |
37 |
Correct |
59 ms |
56020 KB |
Output is correct |
38 |
Correct |
58 ms |
56364 KB |
Output is correct |
39 |
Correct |
60 ms |
56720 KB |
Output is correct |
40 |
Correct |
56 ms |
57220 KB |
Output is correct |
41 |
Correct |
54 ms |
57720 KB |
Output is correct |
42 |
Correct |
55 ms |
57964 KB |
Output is correct |
43 |
Correct |
55 ms |
58376 KB |
Output is correct |
44 |
Correct |
57 ms |
58684 KB |
Output is correct |
45 |
Correct |
56 ms |
59208 KB |
Output is correct |
46 |
Correct |
61 ms |
59404 KB |
Output is correct |
47 |
Correct |
57 ms |
59848 KB |
Output is correct |
48 |
Correct |
232 ms |
79856 KB |
Output is correct |
49 |
Correct |
238 ms |
84392 KB |
Output is correct |
50 |
Correct |
283 ms |
88888 KB |
Output is correct |
51 |
Correct |
190 ms |
93008 KB |
Output is correct |
52 |
Correct |
205 ms |
94568 KB |
Output is correct |
53 |
Correct |
202 ms |
99908 KB |
Output is correct |
54 |
Correct |
180 ms |
102436 KB |
Output is correct |
55 |
Correct |
173 ms |
106536 KB |
Output is correct |
56 |
Correct |
181 ms |
110372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
51192 KB |
Output is correct |
2 |
Correct |
43 ms |
51304 KB |
Output is correct |
3 |
Correct |
42 ms |
51416 KB |
Output is correct |
4 |
Correct |
50 ms |
51552 KB |
Output is correct |
5 |
Correct |
43 ms |
51552 KB |
Output is correct |
6 |
Correct |
43 ms |
51560 KB |
Output is correct |
7 |
Correct |
45 ms |
51576 KB |
Output is correct |
8 |
Correct |
46 ms |
51676 KB |
Output is correct |
9 |
Correct |
43 ms |
51676 KB |
Output is correct |
10 |
Correct |
46 ms |
51676 KB |
Output is correct |
11 |
Correct |
43 ms |
51676 KB |
Output is correct |
12 |
Correct |
46 ms |
51704 KB |
Output is correct |
13 |
Correct |
45 ms |
51704 KB |
Output is correct |
14 |
Correct |
44 ms |
51704 KB |
Output is correct |
15 |
Correct |
47 ms |
51704 KB |
Output is correct |
16 |
Correct |
45 ms |
51704 KB |
Output is correct |
17 |
Correct |
48 ms |
51704 KB |
Output is correct |
18 |
Correct |
47 ms |
51704 KB |
Output is correct |
19 |
Correct |
42 ms |
51704 KB |
Output is correct |
20 |
Correct |
42 ms |
51704 KB |
Output is correct |
21 |
Correct |
45 ms |
51712 KB |
Output is correct |
22 |
Correct |
44 ms |
51744 KB |
Output is correct |
23 |
Correct |
50 ms |
51744 KB |
Output is correct |
24 |
Correct |
45 ms |
51744 KB |
Output is correct |
25 |
Correct |
51 ms |
51744 KB |
Output is correct |
26 |
Correct |
51 ms |
51764 KB |
Output is correct |
27 |
Correct |
53 ms |
53444 KB |
Output is correct |
28 |
Correct |
52 ms |
53528 KB |
Output is correct |
29 |
Correct |
52 ms |
53868 KB |
Output is correct |
30 |
Correct |
52 ms |
53868 KB |
Output is correct |
31 |
Correct |
52 ms |
54404 KB |
Output is correct |
32 |
Correct |
53 ms |
54404 KB |
Output is correct |
33 |
Correct |
53 ms |
54696 KB |
Output is correct |
34 |
Correct |
52 ms |
54696 KB |
Output is correct |
35 |
Correct |
61 ms |
55232 KB |
Output is correct |
36 |
Correct |
62 ms |
55604 KB |
Output is correct |
37 |
Correct |
59 ms |
56020 KB |
Output is correct |
38 |
Correct |
58 ms |
56364 KB |
Output is correct |
39 |
Correct |
60 ms |
56720 KB |
Output is correct |
40 |
Correct |
56 ms |
57220 KB |
Output is correct |
41 |
Correct |
54 ms |
57720 KB |
Output is correct |
42 |
Correct |
55 ms |
57964 KB |
Output is correct |
43 |
Correct |
55 ms |
58376 KB |
Output is correct |
44 |
Correct |
57 ms |
58684 KB |
Output is correct |
45 |
Correct |
56 ms |
59208 KB |
Output is correct |
46 |
Correct |
61 ms |
59404 KB |
Output is correct |
47 |
Correct |
57 ms |
59848 KB |
Output is correct |
48 |
Correct |
232 ms |
79856 KB |
Output is correct |
49 |
Correct |
238 ms |
84392 KB |
Output is correct |
50 |
Correct |
283 ms |
88888 KB |
Output is correct |
51 |
Correct |
190 ms |
93008 KB |
Output is correct |
52 |
Correct |
205 ms |
94568 KB |
Output is correct |
53 |
Correct |
202 ms |
99908 KB |
Output is correct |
54 |
Correct |
180 ms |
102436 KB |
Output is correct |
55 |
Correct |
173 ms |
106536 KB |
Output is correct |
56 |
Correct |
181 ms |
110372 KB |
Output is correct |
57 |
Correct |
1807 ms |
197496 KB |
Output is correct |
58 |
Correct |
1563 ms |
197496 KB |
Output is correct |
59 |
Correct |
1555 ms |
197496 KB |
Output is correct |
60 |
Correct |
1553 ms |
197496 KB |
Output is correct |
61 |
Correct |
1581 ms |
197656 KB |
Output is correct |
62 |
Correct |
644 ms |
197656 KB |
Output is correct |
63 |
Correct |
1059 ms |
197656 KB |
Output is correct |
64 |
Correct |
909 ms |
197656 KB |
Output is correct |
65 |
Correct |
384 ms |
197656 KB |
Output is correct |