#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 1e6 + 5;
int a[N], res[N], cc[N];
map<int, int> edges[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
a[i]--;
cc[a[i]]++;
}
vector<int> tot(m); iota(tot.begin(), tot.end(), 0);
sort(tot.begin(), tot.end(), [&](int i, int j){
if(cc[i] != cc[j]) return cc[i] > cc[j];
return i > j;
});
{
for(int i=1;i+1<n;i+=2){
edges[a[i]][a[i+1]]++;
edges[a[i+1]][a[i]]++;
}
for(int i=0;i<m;i++){
int rr = 0;
edges[i][i] = cc[i];
vector<ar<int, 2>> t;
for(auto x : edges[i]){
t.push_back({x.first, x.second});
}
sort(t.begin(), t.end(), [&](auto& a, auto& b){
if(cc[a[0]] != cc[b[0]]) return cc[a[0]] > cc[b[0]];
return a[0] > b[0];
});
int l = 0;
for(auto x : t){
if(tot[l] == x[0]) l++;
rr = max(rr, cc[x[0]] - x[1]);
}
if(l < m) rr = max(rr, cc[tot[l]]);
res[i] = max(res[i], rr + cc[i]);
edges[i].clear();
}
}
{
for(int i=0;i+1<n;i+=2){
edges[a[i]][a[i+1]]++;
edges[a[i+1]][a[i]]++;
}
for(int i=0;i<m;i++){
int rr = 0;
edges[i][i] = cc[i];
vector<ar<int, 2>> t;
for(auto x : edges[i]){
t.push_back({x.first, x.second});
}
sort(t.begin(), t.end(), [&](auto& a, auto& b){
if(cc[a[0]] != cc[b[0]]) return cc[a[0]] > cc[b[0]];
return a[0] > b[0];
});
int l = 0;
for(auto x : t){
if(tot[l] == x[0]) l++;
rr = max(rr, cc[x[0]] - x[1]);
}
if(l < m) rr = max(rr, cc[tot[l]]);
res[i] = max(res[i], rr + cc[i]);
edges[i].clear();
}
}
for(int i=0;i<m;i++) cout<<n - res[i]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47212 KB |
Output is correct |
3 |
Correct |
24 ms |
47220 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
23 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47224 KB |
Output is correct |
7 |
Correct |
23 ms |
47236 KB |
Output is correct |
8 |
Correct |
28 ms |
47188 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
24 ms |
47228 KB |
Output is correct |
11 |
Correct |
25 ms |
47388 KB |
Output is correct |
12 |
Correct |
24 ms |
47260 KB |
Output is correct |
13 |
Correct |
23 ms |
47272 KB |
Output is correct |
14 |
Correct |
24 ms |
47312 KB |
Output is correct |
15 |
Correct |
23 ms |
47256 KB |
Output is correct |
16 |
Correct |
24 ms |
47264 KB |
Output is correct |
17 |
Correct |
24 ms |
47188 KB |
Output is correct |
18 |
Correct |
24 ms |
47188 KB |
Output is correct |
19 |
Correct |
24 ms |
47236 KB |
Output is correct |
20 |
Correct |
24 ms |
47168 KB |
Output is correct |
21 |
Correct |
23 ms |
47312 KB |
Output is correct |
22 |
Correct |
24 ms |
47220 KB |
Output is correct |
23 |
Correct |
25 ms |
47180 KB |
Output is correct |
24 |
Correct |
24 ms |
47212 KB |
Output is correct |
25 |
Correct |
25 ms |
47312 KB |
Output is correct |
26 |
Correct |
28 ms |
47184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47212 KB |
Output is correct |
3 |
Correct |
24 ms |
47220 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
23 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47224 KB |
Output is correct |
7 |
Correct |
23 ms |
47236 KB |
Output is correct |
8 |
Correct |
28 ms |
47188 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
24 ms |
47228 KB |
Output is correct |
11 |
Correct |
25 ms |
47388 KB |
Output is correct |
12 |
Correct |
24 ms |
47260 KB |
Output is correct |
13 |
Correct |
23 ms |
47272 KB |
Output is correct |
14 |
Correct |
24 ms |
47312 KB |
Output is correct |
15 |
Correct |
23 ms |
47256 KB |
Output is correct |
16 |
Correct |
24 ms |
47264 KB |
Output is correct |
17 |
Correct |
24 ms |
47188 KB |
Output is correct |
18 |
Correct |
24 ms |
47188 KB |
Output is correct |
19 |
Correct |
24 ms |
47236 KB |
Output is correct |
20 |
Correct |
24 ms |
47168 KB |
Output is correct |
21 |
Correct |
23 ms |
47312 KB |
Output is correct |
22 |
Correct |
24 ms |
47220 KB |
Output is correct |
23 |
Correct |
25 ms |
47180 KB |
Output is correct |
24 |
Correct |
24 ms |
47212 KB |
Output is correct |
25 |
Correct |
25 ms |
47312 KB |
Output is correct |
26 |
Correct |
28 ms |
47184 KB |
Output is correct |
27 |
Correct |
37 ms |
47692 KB |
Output is correct |
28 |
Correct |
33 ms |
47692 KB |
Output is correct |
29 |
Correct |
35 ms |
47648 KB |
Output is correct |
30 |
Correct |
32 ms |
47564 KB |
Output is correct |
31 |
Correct |
33 ms |
47688 KB |
Output is correct |
32 |
Correct |
32 ms |
47632 KB |
Output is correct |
33 |
Correct |
33 ms |
47608 KB |
Output is correct |
34 |
Correct |
33 ms |
47664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47212 KB |
Output is correct |
3 |
Correct |
24 ms |
47220 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
23 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47224 KB |
Output is correct |
7 |
Correct |
23 ms |
47236 KB |
Output is correct |
8 |
Correct |
28 ms |
47188 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
24 ms |
47228 KB |
Output is correct |
11 |
Correct |
25 ms |
47388 KB |
Output is correct |
12 |
Correct |
24 ms |
47260 KB |
Output is correct |
13 |
Correct |
23 ms |
47272 KB |
Output is correct |
14 |
Correct |
24 ms |
47312 KB |
Output is correct |
15 |
Correct |
23 ms |
47256 KB |
Output is correct |
16 |
Correct |
24 ms |
47264 KB |
Output is correct |
17 |
Correct |
24 ms |
47188 KB |
Output is correct |
18 |
Correct |
24 ms |
47188 KB |
Output is correct |
19 |
Correct |
24 ms |
47236 KB |
Output is correct |
20 |
Correct |
24 ms |
47168 KB |
Output is correct |
21 |
Correct |
23 ms |
47312 KB |
Output is correct |
22 |
Correct |
24 ms |
47220 KB |
Output is correct |
23 |
Correct |
25 ms |
47180 KB |
Output is correct |
24 |
Correct |
24 ms |
47212 KB |
Output is correct |
25 |
Correct |
25 ms |
47312 KB |
Output is correct |
26 |
Correct |
28 ms |
47184 KB |
Output is correct |
27 |
Correct |
37 ms |
47692 KB |
Output is correct |
28 |
Correct |
33 ms |
47692 KB |
Output is correct |
29 |
Correct |
35 ms |
47648 KB |
Output is correct |
30 |
Correct |
32 ms |
47564 KB |
Output is correct |
31 |
Correct |
33 ms |
47688 KB |
Output is correct |
32 |
Correct |
32 ms |
47632 KB |
Output is correct |
33 |
Correct |
33 ms |
47608 KB |
Output is correct |
34 |
Correct |
33 ms |
47664 KB |
Output is correct |
35 |
Correct |
98 ms |
51488 KB |
Output is correct |
36 |
Correct |
86 ms |
51500 KB |
Output is correct |
37 |
Correct |
84 ms |
51500 KB |
Output is correct |
38 |
Correct |
87 ms |
51584 KB |
Output is correct |
39 |
Correct |
86 ms |
51548 KB |
Output is correct |
40 |
Correct |
54 ms |
49744 KB |
Output is correct |
41 |
Correct |
56 ms |
49592 KB |
Output is correct |
42 |
Correct |
50 ms |
49212 KB |
Output is correct |
43 |
Correct |
55 ms |
49108 KB |
Output is correct |
44 |
Correct |
55 ms |
49712 KB |
Output is correct |
45 |
Correct |
55 ms |
49636 KB |
Output is correct |
46 |
Correct |
50 ms |
49320 KB |
Output is correct |
47 |
Correct |
51 ms |
49228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47212 KB |
Output is correct |
3 |
Correct |
24 ms |
47220 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
23 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47224 KB |
Output is correct |
7 |
Correct |
23 ms |
47236 KB |
Output is correct |
8 |
Correct |
28 ms |
47188 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
24 ms |
47228 KB |
Output is correct |
11 |
Correct |
25 ms |
47388 KB |
Output is correct |
12 |
Correct |
24 ms |
47260 KB |
Output is correct |
13 |
Correct |
23 ms |
47272 KB |
Output is correct |
14 |
Correct |
24 ms |
47312 KB |
Output is correct |
15 |
Correct |
23 ms |
47256 KB |
Output is correct |
16 |
Correct |
24 ms |
47264 KB |
Output is correct |
17 |
Correct |
24 ms |
47188 KB |
Output is correct |
18 |
Correct |
24 ms |
47188 KB |
Output is correct |
19 |
Correct |
24 ms |
47236 KB |
Output is correct |
20 |
Correct |
24 ms |
47168 KB |
Output is correct |
21 |
Correct |
23 ms |
47312 KB |
Output is correct |
22 |
Correct |
24 ms |
47220 KB |
Output is correct |
23 |
Correct |
25 ms |
47180 KB |
Output is correct |
24 |
Correct |
24 ms |
47212 KB |
Output is correct |
25 |
Correct |
25 ms |
47312 KB |
Output is correct |
26 |
Correct |
28 ms |
47184 KB |
Output is correct |
27 |
Correct |
37 ms |
47692 KB |
Output is correct |
28 |
Correct |
33 ms |
47692 KB |
Output is correct |
29 |
Correct |
35 ms |
47648 KB |
Output is correct |
30 |
Correct |
32 ms |
47564 KB |
Output is correct |
31 |
Correct |
33 ms |
47688 KB |
Output is correct |
32 |
Correct |
32 ms |
47632 KB |
Output is correct |
33 |
Correct |
33 ms |
47608 KB |
Output is correct |
34 |
Correct |
33 ms |
47664 KB |
Output is correct |
35 |
Correct |
98 ms |
51488 KB |
Output is correct |
36 |
Correct |
86 ms |
51500 KB |
Output is correct |
37 |
Correct |
84 ms |
51500 KB |
Output is correct |
38 |
Correct |
87 ms |
51584 KB |
Output is correct |
39 |
Correct |
86 ms |
51548 KB |
Output is correct |
40 |
Correct |
54 ms |
49744 KB |
Output is correct |
41 |
Correct |
56 ms |
49592 KB |
Output is correct |
42 |
Correct |
50 ms |
49212 KB |
Output is correct |
43 |
Correct |
55 ms |
49108 KB |
Output is correct |
44 |
Correct |
55 ms |
49712 KB |
Output is correct |
45 |
Correct |
55 ms |
49636 KB |
Output is correct |
46 |
Correct |
50 ms |
49320 KB |
Output is correct |
47 |
Correct |
51 ms |
49228 KB |
Output is correct |
48 |
Correct |
1807 ms |
95724 KB |
Output is correct |
49 |
Correct |
1862 ms |
100200 KB |
Output is correct |
50 |
Correct |
1826 ms |
100276 KB |
Output is correct |
51 |
Correct |
1710 ms |
93396 KB |
Output is correct |
52 |
Correct |
1440 ms |
84772 KB |
Output is correct |
53 |
Correct |
649 ms |
79448 KB |
Output is correct |
54 |
Correct |
442 ms |
73164 KB |
Output is correct |
55 |
Correct |
430 ms |
72620 KB |
Output is correct |
56 |
Correct |
372 ms |
69908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47316 KB |
Output is correct |
2 |
Correct |
23 ms |
47212 KB |
Output is correct |
3 |
Correct |
24 ms |
47220 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
23 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47224 KB |
Output is correct |
7 |
Correct |
23 ms |
47236 KB |
Output is correct |
8 |
Correct |
28 ms |
47188 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
24 ms |
47228 KB |
Output is correct |
11 |
Correct |
25 ms |
47388 KB |
Output is correct |
12 |
Correct |
24 ms |
47260 KB |
Output is correct |
13 |
Correct |
23 ms |
47272 KB |
Output is correct |
14 |
Correct |
24 ms |
47312 KB |
Output is correct |
15 |
Correct |
23 ms |
47256 KB |
Output is correct |
16 |
Correct |
24 ms |
47264 KB |
Output is correct |
17 |
Correct |
24 ms |
47188 KB |
Output is correct |
18 |
Correct |
24 ms |
47188 KB |
Output is correct |
19 |
Correct |
24 ms |
47236 KB |
Output is correct |
20 |
Correct |
24 ms |
47168 KB |
Output is correct |
21 |
Correct |
23 ms |
47312 KB |
Output is correct |
22 |
Correct |
24 ms |
47220 KB |
Output is correct |
23 |
Correct |
25 ms |
47180 KB |
Output is correct |
24 |
Correct |
24 ms |
47212 KB |
Output is correct |
25 |
Correct |
25 ms |
47312 KB |
Output is correct |
26 |
Correct |
28 ms |
47184 KB |
Output is correct |
27 |
Correct |
37 ms |
47692 KB |
Output is correct |
28 |
Correct |
33 ms |
47692 KB |
Output is correct |
29 |
Correct |
35 ms |
47648 KB |
Output is correct |
30 |
Correct |
32 ms |
47564 KB |
Output is correct |
31 |
Correct |
33 ms |
47688 KB |
Output is correct |
32 |
Correct |
32 ms |
47632 KB |
Output is correct |
33 |
Correct |
33 ms |
47608 KB |
Output is correct |
34 |
Correct |
33 ms |
47664 KB |
Output is correct |
35 |
Correct |
98 ms |
51488 KB |
Output is correct |
36 |
Correct |
86 ms |
51500 KB |
Output is correct |
37 |
Correct |
84 ms |
51500 KB |
Output is correct |
38 |
Correct |
87 ms |
51584 KB |
Output is correct |
39 |
Correct |
86 ms |
51548 KB |
Output is correct |
40 |
Correct |
54 ms |
49744 KB |
Output is correct |
41 |
Correct |
56 ms |
49592 KB |
Output is correct |
42 |
Correct |
50 ms |
49212 KB |
Output is correct |
43 |
Correct |
55 ms |
49108 KB |
Output is correct |
44 |
Correct |
55 ms |
49712 KB |
Output is correct |
45 |
Correct |
55 ms |
49636 KB |
Output is correct |
46 |
Correct |
50 ms |
49320 KB |
Output is correct |
47 |
Correct |
51 ms |
49228 KB |
Output is correct |
48 |
Correct |
1807 ms |
95724 KB |
Output is correct |
49 |
Correct |
1862 ms |
100200 KB |
Output is correct |
50 |
Correct |
1826 ms |
100276 KB |
Output is correct |
51 |
Correct |
1710 ms |
93396 KB |
Output is correct |
52 |
Correct |
1440 ms |
84772 KB |
Output is correct |
53 |
Correct |
649 ms |
79448 KB |
Output is correct |
54 |
Correct |
442 ms |
73164 KB |
Output is correct |
55 |
Correct |
430 ms |
72620 KB |
Output is correct |
56 |
Correct |
372 ms |
69908 KB |
Output is correct |
57 |
Correct |
1190 ms |
123680 KB |
Output is correct |
58 |
Correct |
1131 ms |
116044 KB |
Output is correct |
59 |
Correct |
1156 ms |
115976 KB |
Output is correct |
60 |
Correct |
1169 ms |
118044 KB |
Output is correct |
61 |
Correct |
1160 ms |
118080 KB |
Output is correct |
62 |
Correct |
689 ms |
87500 KB |
Output is correct |
63 |
Correct |
940 ms |
98500 KB |
Output is correct |
64 |
Correct |
799 ms |
92804 KB |
Output is correct |
65 |
Correct |
517 ms |
78444 KB |
Output is correct |