#include<bits/stdc++.h>
#define SIZE 1000001
using namespace std;
int N,M,A[SIZE],B[SIZE],C[SIZE],D[SIZE],ans[SIZE];
vector<int>v1[SIZE],v2[SIZE];
set<pair<int,int> >st;
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>A[i];
B[A[i]]++;
}
for(int i=1;i<=M;i++){
st.insert({-B[i],i});
ans[i]=1e9;
}
for(int i=1;i<N;i+=2){
v1[A[i]].push_back(A[i+1]);
v1[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
set<int>u;
C[i]=-B[i];
u.insert(i);
for(int j:v1[i]){
if(u.find(j)==u.end()){
C[j]=-B[j];
u.insert(j);
}
st.erase({C[j],j});
st.insert({++C[j],j});
}
st.erase({C[i],i});
if(!st.empty())ans[i]=min(ans[i],N-B[i]+st.begin()->first);
else ans[i]=0;
st.insert({C[i],i});
for(int j:u){
st.erase({C[j],j});
st.insert({-B[j],j});
}
}
for(int i=2;i<N;i+=2){
v2[A[i]].push_back(A[i+1]);
v2[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
set<int>u;
C[i]=-B[i];
u.insert(i);
for(int j:v2[i]){
if(u.find(j)==u.end()){
C[j]=-B[j];
u.insert(j);
}
st.erase({C[j],j});
st.insert({++C[j],j});
}
st.erase({C[i],i});
if(!st.empty())ans[i]=min(ans[i],N-B[i]+st.begin()->first);
else ans[i]=0;
st.insert({C[i],i});
for(int j:u){
st.erase({C[j],j});
st.insert({-B[j],j});
}
printf("%d\n",ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47316 KB |
Output is correct |
2 |
Correct |
25 ms |
47216 KB |
Output is correct |
3 |
Correct |
31 ms |
47260 KB |
Output is correct |
4 |
Correct |
24 ms |
47216 KB |
Output is correct |
5 |
Correct |
24 ms |
47180 KB |
Output is correct |
6 |
Correct |
24 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47208 KB |
Output is correct |
8 |
Correct |
31 ms |
47184 KB |
Output is correct |
9 |
Correct |
29 ms |
47224 KB |
Output is correct |
10 |
Correct |
26 ms |
47316 KB |
Output is correct |
11 |
Correct |
26 ms |
47316 KB |
Output is correct |
12 |
Correct |
29 ms |
47180 KB |
Output is correct |
13 |
Correct |
26 ms |
47304 KB |
Output is correct |
14 |
Correct |
24 ms |
47316 KB |
Output is correct |
15 |
Correct |
26 ms |
47224 KB |
Output is correct |
16 |
Correct |
29 ms |
47276 KB |
Output is correct |
17 |
Correct |
26 ms |
47300 KB |
Output is correct |
18 |
Correct |
24 ms |
47264 KB |
Output is correct |
19 |
Correct |
27 ms |
47316 KB |
Output is correct |
20 |
Correct |
25 ms |
47232 KB |
Output is correct |
21 |
Correct |
25 ms |
47208 KB |
Output is correct |
22 |
Correct |
27 ms |
47316 KB |
Output is correct |
23 |
Correct |
32 ms |
47180 KB |
Output is correct |
24 |
Correct |
32 ms |
47180 KB |
Output is correct |
25 |
Correct |
23 ms |
47280 KB |
Output is correct |
26 |
Correct |
24 ms |
47244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47316 KB |
Output is correct |
2 |
Correct |
25 ms |
47216 KB |
Output is correct |
3 |
Correct |
31 ms |
47260 KB |
Output is correct |
4 |
Correct |
24 ms |
47216 KB |
Output is correct |
5 |
Correct |
24 ms |
47180 KB |
Output is correct |
6 |
Correct |
24 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47208 KB |
Output is correct |
8 |
Correct |
31 ms |
47184 KB |
Output is correct |
9 |
Correct |
29 ms |
47224 KB |
Output is correct |
10 |
Correct |
26 ms |
47316 KB |
Output is correct |
11 |
Correct |
26 ms |
47316 KB |
Output is correct |
12 |
Correct |
29 ms |
47180 KB |
Output is correct |
13 |
Correct |
26 ms |
47304 KB |
Output is correct |
14 |
Correct |
24 ms |
47316 KB |
Output is correct |
15 |
Correct |
26 ms |
47224 KB |
Output is correct |
16 |
Correct |
29 ms |
47276 KB |
Output is correct |
17 |
Correct |
26 ms |
47300 KB |
Output is correct |
18 |
Correct |
24 ms |
47264 KB |
Output is correct |
19 |
Correct |
27 ms |
47316 KB |
Output is correct |
20 |
Correct |
25 ms |
47232 KB |
Output is correct |
21 |
Correct |
25 ms |
47208 KB |
Output is correct |
22 |
Correct |
27 ms |
47316 KB |
Output is correct |
23 |
Correct |
32 ms |
47180 KB |
Output is correct |
24 |
Correct |
32 ms |
47180 KB |
Output is correct |
25 |
Correct |
23 ms |
47280 KB |
Output is correct |
26 |
Correct |
24 ms |
47244 KB |
Output is correct |
27 |
Correct |
50 ms |
48872 KB |
Output is correct |
28 |
Correct |
51 ms |
48636 KB |
Output is correct |
29 |
Correct |
67 ms |
48864 KB |
Output is correct |
30 |
Correct |
49 ms |
48836 KB |
Output is correct |
31 |
Correct |
53 ms |
48912 KB |
Output is correct |
32 |
Correct |
45 ms |
48752 KB |
Output is correct |
33 |
Correct |
49 ms |
48784 KB |
Output is correct |
34 |
Correct |
50 ms |
48800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47316 KB |
Output is correct |
2 |
Correct |
25 ms |
47216 KB |
Output is correct |
3 |
Correct |
31 ms |
47260 KB |
Output is correct |
4 |
Correct |
24 ms |
47216 KB |
Output is correct |
5 |
Correct |
24 ms |
47180 KB |
Output is correct |
6 |
Correct |
24 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47208 KB |
Output is correct |
8 |
Correct |
31 ms |
47184 KB |
Output is correct |
9 |
Correct |
29 ms |
47224 KB |
Output is correct |
10 |
Correct |
26 ms |
47316 KB |
Output is correct |
11 |
Correct |
26 ms |
47316 KB |
Output is correct |
12 |
Correct |
29 ms |
47180 KB |
Output is correct |
13 |
Correct |
26 ms |
47304 KB |
Output is correct |
14 |
Correct |
24 ms |
47316 KB |
Output is correct |
15 |
Correct |
26 ms |
47224 KB |
Output is correct |
16 |
Correct |
29 ms |
47276 KB |
Output is correct |
17 |
Correct |
26 ms |
47300 KB |
Output is correct |
18 |
Correct |
24 ms |
47264 KB |
Output is correct |
19 |
Correct |
27 ms |
47316 KB |
Output is correct |
20 |
Correct |
25 ms |
47232 KB |
Output is correct |
21 |
Correct |
25 ms |
47208 KB |
Output is correct |
22 |
Correct |
27 ms |
47316 KB |
Output is correct |
23 |
Correct |
32 ms |
47180 KB |
Output is correct |
24 |
Correct |
32 ms |
47180 KB |
Output is correct |
25 |
Correct |
23 ms |
47280 KB |
Output is correct |
26 |
Correct |
24 ms |
47244 KB |
Output is correct |
27 |
Correct |
50 ms |
48872 KB |
Output is correct |
28 |
Correct |
51 ms |
48636 KB |
Output is correct |
29 |
Correct |
67 ms |
48864 KB |
Output is correct |
30 |
Correct |
49 ms |
48836 KB |
Output is correct |
31 |
Correct |
53 ms |
48912 KB |
Output is correct |
32 |
Correct |
45 ms |
48752 KB |
Output is correct |
33 |
Correct |
49 ms |
48784 KB |
Output is correct |
34 |
Correct |
50 ms |
48800 KB |
Output is correct |
35 |
Correct |
166 ms |
48824 KB |
Output is correct |
36 |
Correct |
153 ms |
48820 KB |
Output is correct |
37 |
Correct |
164 ms |
48800 KB |
Output is correct |
38 |
Correct |
171 ms |
48812 KB |
Output is correct |
39 |
Correct |
155 ms |
48824 KB |
Output is correct |
40 |
Correct |
127 ms |
49152 KB |
Output is correct |
41 |
Correct |
127 ms |
48976 KB |
Output is correct |
42 |
Correct |
119 ms |
48904 KB |
Output is correct |
43 |
Correct |
124 ms |
49032 KB |
Output is correct |
44 |
Correct |
118 ms |
49012 KB |
Output is correct |
45 |
Correct |
120 ms |
48912 KB |
Output is correct |
46 |
Correct |
126 ms |
48864 KB |
Output is correct |
47 |
Correct |
117 ms |
48924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47316 KB |
Output is correct |
2 |
Correct |
25 ms |
47216 KB |
Output is correct |
3 |
Correct |
31 ms |
47260 KB |
Output is correct |
4 |
Correct |
24 ms |
47216 KB |
Output is correct |
5 |
Correct |
24 ms |
47180 KB |
Output is correct |
6 |
Correct |
24 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47208 KB |
Output is correct |
8 |
Correct |
31 ms |
47184 KB |
Output is correct |
9 |
Correct |
29 ms |
47224 KB |
Output is correct |
10 |
Correct |
26 ms |
47316 KB |
Output is correct |
11 |
Correct |
26 ms |
47316 KB |
Output is correct |
12 |
Correct |
29 ms |
47180 KB |
Output is correct |
13 |
Correct |
26 ms |
47304 KB |
Output is correct |
14 |
Correct |
24 ms |
47316 KB |
Output is correct |
15 |
Correct |
26 ms |
47224 KB |
Output is correct |
16 |
Correct |
29 ms |
47276 KB |
Output is correct |
17 |
Correct |
26 ms |
47300 KB |
Output is correct |
18 |
Correct |
24 ms |
47264 KB |
Output is correct |
19 |
Correct |
27 ms |
47316 KB |
Output is correct |
20 |
Correct |
25 ms |
47232 KB |
Output is correct |
21 |
Correct |
25 ms |
47208 KB |
Output is correct |
22 |
Correct |
27 ms |
47316 KB |
Output is correct |
23 |
Correct |
32 ms |
47180 KB |
Output is correct |
24 |
Correct |
32 ms |
47180 KB |
Output is correct |
25 |
Correct |
23 ms |
47280 KB |
Output is correct |
26 |
Correct |
24 ms |
47244 KB |
Output is correct |
27 |
Correct |
50 ms |
48872 KB |
Output is correct |
28 |
Correct |
51 ms |
48636 KB |
Output is correct |
29 |
Correct |
67 ms |
48864 KB |
Output is correct |
30 |
Correct |
49 ms |
48836 KB |
Output is correct |
31 |
Correct |
53 ms |
48912 KB |
Output is correct |
32 |
Correct |
45 ms |
48752 KB |
Output is correct |
33 |
Correct |
49 ms |
48784 KB |
Output is correct |
34 |
Correct |
50 ms |
48800 KB |
Output is correct |
35 |
Correct |
166 ms |
48824 KB |
Output is correct |
36 |
Correct |
153 ms |
48820 KB |
Output is correct |
37 |
Correct |
164 ms |
48800 KB |
Output is correct |
38 |
Correct |
171 ms |
48812 KB |
Output is correct |
39 |
Correct |
155 ms |
48824 KB |
Output is correct |
40 |
Correct |
127 ms |
49152 KB |
Output is correct |
41 |
Correct |
127 ms |
48976 KB |
Output is correct |
42 |
Correct |
119 ms |
48904 KB |
Output is correct |
43 |
Correct |
124 ms |
49032 KB |
Output is correct |
44 |
Correct |
118 ms |
49012 KB |
Output is correct |
45 |
Correct |
120 ms |
48912 KB |
Output is correct |
46 |
Correct |
126 ms |
48864 KB |
Output is correct |
47 |
Correct |
117 ms |
48924 KB |
Output is correct |
48 |
Correct |
1731 ms |
64552 KB |
Output is correct |
49 |
Correct |
1707 ms |
64524 KB |
Output is correct |
50 |
Correct |
1725 ms |
64600 KB |
Output is correct |
51 |
Correct |
1636 ms |
64432 KB |
Output is correct |
52 |
Correct |
1390 ms |
62092 KB |
Output is correct |
53 |
Correct |
1258 ms |
63016 KB |
Output is correct |
54 |
Correct |
1099 ms |
60972 KB |
Output is correct |
55 |
Correct |
1098 ms |
60644 KB |
Output is correct |
56 |
Correct |
1078 ms |
60112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47316 KB |
Output is correct |
2 |
Correct |
25 ms |
47216 KB |
Output is correct |
3 |
Correct |
31 ms |
47260 KB |
Output is correct |
4 |
Correct |
24 ms |
47216 KB |
Output is correct |
5 |
Correct |
24 ms |
47180 KB |
Output is correct |
6 |
Correct |
24 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47208 KB |
Output is correct |
8 |
Correct |
31 ms |
47184 KB |
Output is correct |
9 |
Correct |
29 ms |
47224 KB |
Output is correct |
10 |
Correct |
26 ms |
47316 KB |
Output is correct |
11 |
Correct |
26 ms |
47316 KB |
Output is correct |
12 |
Correct |
29 ms |
47180 KB |
Output is correct |
13 |
Correct |
26 ms |
47304 KB |
Output is correct |
14 |
Correct |
24 ms |
47316 KB |
Output is correct |
15 |
Correct |
26 ms |
47224 KB |
Output is correct |
16 |
Correct |
29 ms |
47276 KB |
Output is correct |
17 |
Correct |
26 ms |
47300 KB |
Output is correct |
18 |
Correct |
24 ms |
47264 KB |
Output is correct |
19 |
Correct |
27 ms |
47316 KB |
Output is correct |
20 |
Correct |
25 ms |
47232 KB |
Output is correct |
21 |
Correct |
25 ms |
47208 KB |
Output is correct |
22 |
Correct |
27 ms |
47316 KB |
Output is correct |
23 |
Correct |
32 ms |
47180 KB |
Output is correct |
24 |
Correct |
32 ms |
47180 KB |
Output is correct |
25 |
Correct |
23 ms |
47280 KB |
Output is correct |
26 |
Correct |
24 ms |
47244 KB |
Output is correct |
27 |
Correct |
50 ms |
48872 KB |
Output is correct |
28 |
Correct |
51 ms |
48636 KB |
Output is correct |
29 |
Correct |
67 ms |
48864 KB |
Output is correct |
30 |
Correct |
49 ms |
48836 KB |
Output is correct |
31 |
Correct |
53 ms |
48912 KB |
Output is correct |
32 |
Correct |
45 ms |
48752 KB |
Output is correct |
33 |
Correct |
49 ms |
48784 KB |
Output is correct |
34 |
Correct |
50 ms |
48800 KB |
Output is correct |
35 |
Correct |
166 ms |
48824 KB |
Output is correct |
36 |
Correct |
153 ms |
48820 KB |
Output is correct |
37 |
Correct |
164 ms |
48800 KB |
Output is correct |
38 |
Correct |
171 ms |
48812 KB |
Output is correct |
39 |
Correct |
155 ms |
48824 KB |
Output is correct |
40 |
Correct |
127 ms |
49152 KB |
Output is correct |
41 |
Correct |
127 ms |
48976 KB |
Output is correct |
42 |
Correct |
119 ms |
48904 KB |
Output is correct |
43 |
Correct |
124 ms |
49032 KB |
Output is correct |
44 |
Correct |
118 ms |
49012 KB |
Output is correct |
45 |
Correct |
120 ms |
48912 KB |
Output is correct |
46 |
Correct |
126 ms |
48864 KB |
Output is correct |
47 |
Correct |
117 ms |
48924 KB |
Output is correct |
48 |
Correct |
1731 ms |
64552 KB |
Output is correct |
49 |
Correct |
1707 ms |
64524 KB |
Output is correct |
50 |
Correct |
1725 ms |
64600 KB |
Output is correct |
51 |
Correct |
1636 ms |
64432 KB |
Output is correct |
52 |
Correct |
1390 ms |
62092 KB |
Output is correct |
53 |
Correct |
1258 ms |
63016 KB |
Output is correct |
54 |
Correct |
1099 ms |
60972 KB |
Output is correct |
55 |
Correct |
1098 ms |
60644 KB |
Output is correct |
56 |
Correct |
1078 ms |
60112 KB |
Output is correct |
57 |
Execution timed out |
2576 ms |
141116 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |