#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;
int n, m, a[1000005];
int ans[1000005], occ[1000005], chk[1000005];
vector<int> pnt[1000005];
vector<pi> v;
void solve(int s, int e){
if(e - s + 1 < 0) return;
for(int i=1; i<=m; i++) pnt[i].clear();
if(s > 1) pnt[a[s-1]].push_back(a[s-1]);
if(e < n) pnt[a[e+1]].push_back(a[e+1]);
for(int i=s+1; i<=e; i+=2){
if(a[i-1] == a[i]){
pnt[a[i]].push_back(a[i]);
pnt[a[i]].push_back(a[i]);
}
else{
int x = a[i-1], y = a[i];
pnt[x].push_back(x);
pnt[x].push_back(y);
pnt[y].push_back(x);
pnt[y].push_back(y);
}
}
for(int i=1; i<=m; i++){
int cur = -1e9;
for(auto &j : pnt[i]) chk[j]++;
for(auto &j : v){
cur = max(cur, j.first - chk[j.second]);
if(!chk[j.second]) break;
}
for(auto &j : pnt[i]) chk[j]--;
ans[i] = min(ans[i], n - occ[i] - cur);
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
memset(ans, 0x3f, sizeof(ans));
for(int i=1; i<=n; i++) occ[a[i]]++;
for(int i=1; i<=m; i++) v.push_back(pi(occ[i], i));
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
if(n % 2 == 0) solve(1, n), solve(2, n-1);
else solve(1, n-1), solve(2, n);
for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:42:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&m);
^
rope.cpp:44:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
13 ms |
41084 KB |
Output is correct |
4 |
Correct |
9 ms |
41084 KB |
Output is correct |
5 |
Correct |
9 ms |
41084 KB |
Output is correct |
6 |
Correct |
13 ms |
41084 KB |
Output is correct |
7 |
Correct |
9 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
3 ms |
41084 KB |
Output is correct |
11 |
Correct |
6 ms |
41084 KB |
Output is correct |
12 |
Correct |
6 ms |
41084 KB |
Output is correct |
13 |
Correct |
3 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
3 ms |
41084 KB |
Output is correct |
18 |
Correct |
6 ms |
41084 KB |
Output is correct |
19 |
Correct |
6 ms |
41084 KB |
Output is correct |
20 |
Correct |
6 ms |
41084 KB |
Output is correct |
21 |
Correct |
6 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
3 ms |
41084 KB |
Output is correct |
24 |
Correct |
3 ms |
41084 KB |
Output is correct |
25 |
Correct |
3 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
13 ms |
41084 KB |
Output is correct |
4 |
Correct |
9 ms |
41084 KB |
Output is correct |
5 |
Correct |
9 ms |
41084 KB |
Output is correct |
6 |
Correct |
13 ms |
41084 KB |
Output is correct |
7 |
Correct |
9 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
3 ms |
41084 KB |
Output is correct |
11 |
Correct |
6 ms |
41084 KB |
Output is correct |
12 |
Correct |
6 ms |
41084 KB |
Output is correct |
13 |
Correct |
3 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
3 ms |
41084 KB |
Output is correct |
18 |
Correct |
6 ms |
41084 KB |
Output is correct |
19 |
Correct |
6 ms |
41084 KB |
Output is correct |
20 |
Correct |
6 ms |
41084 KB |
Output is correct |
21 |
Correct |
6 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
3 ms |
41084 KB |
Output is correct |
24 |
Correct |
3 ms |
41084 KB |
Output is correct |
25 |
Correct |
3 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
16 ms |
42556 KB |
Output is correct |
28 |
Correct |
16 ms |
42332 KB |
Output is correct |
29 |
Correct |
13 ms |
42516 KB |
Output is correct |
30 |
Correct |
13 ms |
42852 KB |
Output is correct |
31 |
Correct |
16 ms |
42564 KB |
Output is correct |
32 |
Correct |
13 ms |
42200 KB |
Output is correct |
33 |
Correct |
19 ms |
42276 KB |
Output is correct |
34 |
Correct |
19 ms |
42588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
13 ms |
41084 KB |
Output is correct |
4 |
Correct |
9 ms |
41084 KB |
Output is correct |
5 |
Correct |
9 ms |
41084 KB |
Output is correct |
6 |
Correct |
13 ms |
41084 KB |
Output is correct |
7 |
Correct |
9 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
3 ms |
41084 KB |
Output is correct |
11 |
Correct |
6 ms |
41084 KB |
Output is correct |
12 |
Correct |
6 ms |
41084 KB |
Output is correct |
13 |
Correct |
3 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
3 ms |
41084 KB |
Output is correct |
18 |
Correct |
6 ms |
41084 KB |
Output is correct |
19 |
Correct |
6 ms |
41084 KB |
Output is correct |
20 |
Correct |
6 ms |
41084 KB |
Output is correct |
21 |
Correct |
6 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
3 ms |
41084 KB |
Output is correct |
24 |
Correct |
3 ms |
41084 KB |
Output is correct |
25 |
Correct |
3 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
16 ms |
42556 KB |
Output is correct |
28 |
Correct |
16 ms |
42332 KB |
Output is correct |
29 |
Correct |
13 ms |
42516 KB |
Output is correct |
30 |
Correct |
13 ms |
42852 KB |
Output is correct |
31 |
Correct |
16 ms |
42564 KB |
Output is correct |
32 |
Correct |
13 ms |
42200 KB |
Output is correct |
33 |
Correct |
19 ms |
42276 KB |
Output is correct |
34 |
Correct |
19 ms |
42588 KB |
Output is correct |
35 |
Correct |
23 ms |
42140 KB |
Output is correct |
36 |
Correct |
16 ms |
42272 KB |
Output is correct |
37 |
Correct |
23 ms |
42140 KB |
Output is correct |
38 |
Correct |
19 ms |
42140 KB |
Output is correct |
39 |
Correct |
29 ms |
42272 KB |
Output is correct |
40 |
Correct |
19 ms |
42416 KB |
Output is correct |
41 |
Correct |
19 ms |
42420 KB |
Output is correct |
42 |
Correct |
19 ms |
42280 KB |
Output is correct |
43 |
Correct |
16 ms |
42420 KB |
Output is correct |
44 |
Correct |
26 ms |
42416 KB |
Output is correct |
45 |
Correct |
16 ms |
42408 KB |
Output is correct |
46 |
Correct |
19 ms |
42280 KB |
Output is correct |
47 |
Correct |
26 ms |
42420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
13 ms |
41084 KB |
Output is correct |
4 |
Correct |
9 ms |
41084 KB |
Output is correct |
5 |
Correct |
9 ms |
41084 KB |
Output is correct |
6 |
Correct |
13 ms |
41084 KB |
Output is correct |
7 |
Correct |
9 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
3 ms |
41084 KB |
Output is correct |
11 |
Correct |
6 ms |
41084 KB |
Output is correct |
12 |
Correct |
6 ms |
41084 KB |
Output is correct |
13 |
Correct |
3 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
3 ms |
41084 KB |
Output is correct |
18 |
Correct |
6 ms |
41084 KB |
Output is correct |
19 |
Correct |
6 ms |
41084 KB |
Output is correct |
20 |
Correct |
6 ms |
41084 KB |
Output is correct |
21 |
Correct |
6 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
3 ms |
41084 KB |
Output is correct |
24 |
Correct |
3 ms |
41084 KB |
Output is correct |
25 |
Correct |
3 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
16 ms |
42556 KB |
Output is correct |
28 |
Correct |
16 ms |
42332 KB |
Output is correct |
29 |
Correct |
13 ms |
42516 KB |
Output is correct |
30 |
Correct |
13 ms |
42852 KB |
Output is correct |
31 |
Correct |
16 ms |
42564 KB |
Output is correct |
32 |
Correct |
13 ms |
42200 KB |
Output is correct |
33 |
Correct |
19 ms |
42276 KB |
Output is correct |
34 |
Correct |
19 ms |
42588 KB |
Output is correct |
35 |
Correct |
23 ms |
42140 KB |
Output is correct |
36 |
Correct |
16 ms |
42272 KB |
Output is correct |
37 |
Correct |
23 ms |
42140 KB |
Output is correct |
38 |
Correct |
19 ms |
42140 KB |
Output is correct |
39 |
Correct |
29 ms |
42272 KB |
Output is correct |
40 |
Correct |
19 ms |
42416 KB |
Output is correct |
41 |
Correct |
19 ms |
42420 KB |
Output is correct |
42 |
Correct |
19 ms |
42280 KB |
Output is correct |
43 |
Correct |
16 ms |
42420 KB |
Output is correct |
44 |
Correct |
26 ms |
42416 KB |
Output is correct |
45 |
Correct |
16 ms |
42408 KB |
Output is correct |
46 |
Correct |
19 ms |
42280 KB |
Output is correct |
47 |
Correct |
26 ms |
42420 KB |
Output is correct |
48 |
Correct |
223 ms |
54292 KB |
Output is correct |
49 |
Correct |
196 ms |
54160 KB |
Output is correct |
50 |
Correct |
219 ms |
54160 KB |
Output is correct |
51 |
Correct |
179 ms |
54196 KB |
Output is correct |
52 |
Correct |
176 ms |
52364 KB |
Output is correct |
53 |
Correct |
189 ms |
52632 KB |
Output is correct |
54 |
Correct |
166 ms |
50688 KB |
Output is correct |
55 |
Correct |
176 ms |
50300 KB |
Output is correct |
56 |
Correct |
183 ms |
49784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
13 ms |
41084 KB |
Output is correct |
4 |
Correct |
9 ms |
41084 KB |
Output is correct |
5 |
Correct |
9 ms |
41084 KB |
Output is correct |
6 |
Correct |
13 ms |
41084 KB |
Output is correct |
7 |
Correct |
9 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
3 ms |
41084 KB |
Output is correct |
11 |
Correct |
6 ms |
41084 KB |
Output is correct |
12 |
Correct |
6 ms |
41084 KB |
Output is correct |
13 |
Correct |
3 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
3 ms |
41084 KB |
Output is correct |
18 |
Correct |
6 ms |
41084 KB |
Output is correct |
19 |
Correct |
6 ms |
41084 KB |
Output is correct |
20 |
Correct |
6 ms |
41084 KB |
Output is correct |
21 |
Correct |
6 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
3 ms |
41084 KB |
Output is correct |
24 |
Correct |
3 ms |
41084 KB |
Output is correct |
25 |
Correct |
3 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
16 ms |
42556 KB |
Output is correct |
28 |
Correct |
16 ms |
42332 KB |
Output is correct |
29 |
Correct |
13 ms |
42516 KB |
Output is correct |
30 |
Correct |
13 ms |
42852 KB |
Output is correct |
31 |
Correct |
16 ms |
42564 KB |
Output is correct |
32 |
Correct |
13 ms |
42200 KB |
Output is correct |
33 |
Correct |
19 ms |
42276 KB |
Output is correct |
34 |
Correct |
19 ms |
42588 KB |
Output is correct |
35 |
Correct |
23 ms |
42140 KB |
Output is correct |
36 |
Correct |
16 ms |
42272 KB |
Output is correct |
37 |
Correct |
23 ms |
42140 KB |
Output is correct |
38 |
Correct |
19 ms |
42140 KB |
Output is correct |
39 |
Correct |
29 ms |
42272 KB |
Output is correct |
40 |
Correct |
19 ms |
42416 KB |
Output is correct |
41 |
Correct |
19 ms |
42420 KB |
Output is correct |
42 |
Correct |
19 ms |
42280 KB |
Output is correct |
43 |
Correct |
16 ms |
42420 KB |
Output is correct |
44 |
Correct |
26 ms |
42416 KB |
Output is correct |
45 |
Correct |
16 ms |
42408 KB |
Output is correct |
46 |
Correct |
19 ms |
42280 KB |
Output is correct |
47 |
Correct |
26 ms |
42420 KB |
Output is correct |
48 |
Correct |
223 ms |
54292 KB |
Output is correct |
49 |
Correct |
196 ms |
54160 KB |
Output is correct |
50 |
Correct |
219 ms |
54160 KB |
Output is correct |
51 |
Correct |
179 ms |
54196 KB |
Output is correct |
52 |
Correct |
176 ms |
52364 KB |
Output is correct |
53 |
Correct |
189 ms |
52632 KB |
Output is correct |
54 |
Correct |
166 ms |
50688 KB |
Output is correct |
55 |
Correct |
176 ms |
50300 KB |
Output is correct |
56 |
Correct |
183 ms |
49784 KB |
Output is correct |
57 |
Correct |
1396 ms |
80508 KB |
Output is correct |
58 |
Correct |
1206 ms |
69552 KB |
Output is correct |
59 |
Correct |
1056 ms |
69420 KB |
Output is correct |
60 |
Correct |
1049 ms |
71928 KB |
Output is correct |
61 |
Correct |
1149 ms |
71928 KB |
Output is correct |
62 |
Correct |
396 ms |
61020 KB |
Output is correct |
63 |
Correct |
686 ms |
63964 KB |
Output is correct |
64 |
Correct |
526 ms |
62168 KB |
Output is correct |
65 |
Correct |
296 ms |
55312 KB |
Output is correct |