#include <iostream>
#include <vector>
#define MAXN 1000005
using namespace std;
int N, M, C[MAXN], Val[MAXN][2], Ans[MAXN];
vector <int> Pairs[MAXN][2];
class segtree {
int ST[MAXN * 2];
public:
void upd(int ind, int val) {
for (ind += M, ST[ind] += val; ind > 1; ind >>= 1) {
ST[ind >> 1] = max(ST[ind], ST[ind ^ 1]);
}
}
int get() {return(ST[1]);}
} ST1, ST2;
int main() {
//freopen("ropein.txt","r",stdin);
scanf("%d %d",&N,&M);
for (int i=1; i<=M; i++) {
Ans[i] = N;
}
for (int i=1; i<=N; i++) {
scanf("%d",&C[i]);
Ans[C[i]] -= 1;
}
for (int i=1; i<N; i+=2) {
Pairs[C[i]][0].push_back(C[i+1]);
Pairs[C[i+1]][0].push_back(C[i]);
Val[C[i]][0]++, Val[C[i+1]][0]++;
}
for (int i=2; i<N; i+=2) {
Pairs[C[i]][1].push_back(C[i+1]);
Pairs[C[i+1]][1].push_back(C[i]);
Val[C[i]][1]++, Val[C[i+1]][1]++;
}
if (N%2) {
Val[C[N]][0]++, Val[C[1]][1]++;
} else {
Val[C[1]][1]++, Val[C[N]][1]++;
}
for (int i=1; i<=M; i++) {
ST1.upd(i, Val[i][0]);
ST2.upd(i, Val[i][1]);
}
for (int i=1; i<=M; i++) {
//solve case 1
for (int v: Pairs[i][0]) {
ST1.upd(v, -1);
}
ST1.upd(i, -1<<20);
Ans[i] = min(Ans[i], N - ST1.get() - Val[i][0]);
for (int v: Pairs[i][0]) {
ST1.upd(v, 1);
}
ST1.upd(i, 1<<20);
//solve case 2:
for (int v: Pairs[i][1]) {
ST2.upd(v, -1);
}
ST2.upd(i, -1<<20);
Ans[i] = min(Ans[i], N - ST2.get() - Val[i][1]);
for (int v: Pairs[i][1]) {
ST2.upd(v, 1);
}
ST2.upd(i, 1<<20);
}
for (int i=1; i<=M; i++) {
printf("%d\n",Ans[i]);
}
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
21 | scanf("%d %d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~~
rope.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%d",&C[i]);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47280 KB |
Output is correct |
2 |
Correct |
31 ms |
47360 KB |
Output is correct |
3 |
Correct |
30 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
32 ms |
47352 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
31 ms |
47352 KB |
Output is correct |
10 |
Correct |
30 ms |
47360 KB |
Output is correct |
11 |
Correct |
34 ms |
47360 KB |
Output is correct |
12 |
Correct |
31 ms |
47360 KB |
Output is correct |
13 |
Correct |
32 ms |
47360 KB |
Output is correct |
14 |
Correct |
35 ms |
47352 KB |
Output is correct |
15 |
Correct |
34 ms |
47264 KB |
Output is correct |
16 |
Correct |
34 ms |
47352 KB |
Output is correct |
17 |
Correct |
35 ms |
47352 KB |
Output is correct |
18 |
Correct |
31 ms |
47360 KB |
Output is correct |
19 |
Correct |
30 ms |
47352 KB |
Output is correct |
20 |
Correct |
35 ms |
47352 KB |
Output is correct |
21 |
Correct |
31 ms |
47352 KB |
Output is correct |
22 |
Correct |
32 ms |
47364 KB |
Output is correct |
23 |
Correct |
33 ms |
47352 KB |
Output is correct |
24 |
Correct |
30 ms |
47360 KB |
Output is correct |
25 |
Correct |
30 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47280 KB |
Output is correct |
2 |
Correct |
31 ms |
47360 KB |
Output is correct |
3 |
Correct |
30 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
32 ms |
47352 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
31 ms |
47352 KB |
Output is correct |
10 |
Correct |
30 ms |
47360 KB |
Output is correct |
11 |
Correct |
34 ms |
47360 KB |
Output is correct |
12 |
Correct |
31 ms |
47360 KB |
Output is correct |
13 |
Correct |
32 ms |
47360 KB |
Output is correct |
14 |
Correct |
35 ms |
47352 KB |
Output is correct |
15 |
Correct |
34 ms |
47264 KB |
Output is correct |
16 |
Correct |
34 ms |
47352 KB |
Output is correct |
17 |
Correct |
35 ms |
47352 KB |
Output is correct |
18 |
Correct |
31 ms |
47360 KB |
Output is correct |
19 |
Correct |
30 ms |
47352 KB |
Output is correct |
20 |
Correct |
35 ms |
47352 KB |
Output is correct |
21 |
Correct |
31 ms |
47352 KB |
Output is correct |
22 |
Correct |
32 ms |
47364 KB |
Output is correct |
23 |
Correct |
33 ms |
47352 KB |
Output is correct |
24 |
Correct |
30 ms |
47360 KB |
Output is correct |
25 |
Correct |
30 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47356 KB |
Output is correct |
27 |
Correct |
48 ms |
49128 KB |
Output is correct |
28 |
Correct |
46 ms |
48916 KB |
Output is correct |
29 |
Correct |
48 ms |
49016 KB |
Output is correct |
30 |
Correct |
53 ms |
49016 KB |
Output is correct |
31 |
Correct |
55 ms |
49016 KB |
Output is correct |
32 |
Correct |
52 ms |
48956 KB |
Output is correct |
33 |
Correct |
54 ms |
49016 KB |
Output is correct |
34 |
Correct |
56 ms |
49144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47280 KB |
Output is correct |
2 |
Correct |
31 ms |
47360 KB |
Output is correct |
3 |
Correct |
30 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
32 ms |
47352 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
31 ms |
47352 KB |
Output is correct |
10 |
Correct |
30 ms |
47360 KB |
Output is correct |
11 |
Correct |
34 ms |
47360 KB |
Output is correct |
12 |
Correct |
31 ms |
47360 KB |
Output is correct |
13 |
Correct |
32 ms |
47360 KB |
Output is correct |
14 |
Correct |
35 ms |
47352 KB |
Output is correct |
15 |
Correct |
34 ms |
47264 KB |
Output is correct |
16 |
Correct |
34 ms |
47352 KB |
Output is correct |
17 |
Correct |
35 ms |
47352 KB |
Output is correct |
18 |
Correct |
31 ms |
47360 KB |
Output is correct |
19 |
Correct |
30 ms |
47352 KB |
Output is correct |
20 |
Correct |
35 ms |
47352 KB |
Output is correct |
21 |
Correct |
31 ms |
47352 KB |
Output is correct |
22 |
Correct |
32 ms |
47364 KB |
Output is correct |
23 |
Correct |
33 ms |
47352 KB |
Output is correct |
24 |
Correct |
30 ms |
47360 KB |
Output is correct |
25 |
Correct |
30 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47356 KB |
Output is correct |
27 |
Correct |
48 ms |
49128 KB |
Output is correct |
28 |
Correct |
46 ms |
48916 KB |
Output is correct |
29 |
Correct |
48 ms |
49016 KB |
Output is correct |
30 |
Correct |
53 ms |
49016 KB |
Output is correct |
31 |
Correct |
55 ms |
49016 KB |
Output is correct |
32 |
Correct |
52 ms |
48956 KB |
Output is correct |
33 |
Correct |
54 ms |
49016 KB |
Output is correct |
34 |
Correct |
56 ms |
49144 KB |
Output is correct |
35 |
Correct |
56 ms |
49144 KB |
Output is correct |
36 |
Correct |
52 ms |
49144 KB |
Output is correct |
37 |
Correct |
52 ms |
49144 KB |
Output is correct |
38 |
Correct |
52 ms |
49152 KB |
Output is correct |
39 |
Correct |
52 ms |
49144 KB |
Output is correct |
40 |
Correct |
52 ms |
49388 KB |
Output is correct |
41 |
Correct |
53 ms |
49400 KB |
Output is correct |
42 |
Correct |
55 ms |
49272 KB |
Output is correct |
43 |
Correct |
52 ms |
49400 KB |
Output is correct |
44 |
Correct |
53 ms |
49400 KB |
Output is correct |
45 |
Correct |
53 ms |
49400 KB |
Output is correct |
46 |
Correct |
53 ms |
49272 KB |
Output is correct |
47 |
Correct |
52 ms |
49400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47280 KB |
Output is correct |
2 |
Correct |
31 ms |
47360 KB |
Output is correct |
3 |
Correct |
30 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
32 ms |
47352 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
31 ms |
47352 KB |
Output is correct |
10 |
Correct |
30 ms |
47360 KB |
Output is correct |
11 |
Correct |
34 ms |
47360 KB |
Output is correct |
12 |
Correct |
31 ms |
47360 KB |
Output is correct |
13 |
Correct |
32 ms |
47360 KB |
Output is correct |
14 |
Correct |
35 ms |
47352 KB |
Output is correct |
15 |
Correct |
34 ms |
47264 KB |
Output is correct |
16 |
Correct |
34 ms |
47352 KB |
Output is correct |
17 |
Correct |
35 ms |
47352 KB |
Output is correct |
18 |
Correct |
31 ms |
47360 KB |
Output is correct |
19 |
Correct |
30 ms |
47352 KB |
Output is correct |
20 |
Correct |
35 ms |
47352 KB |
Output is correct |
21 |
Correct |
31 ms |
47352 KB |
Output is correct |
22 |
Correct |
32 ms |
47364 KB |
Output is correct |
23 |
Correct |
33 ms |
47352 KB |
Output is correct |
24 |
Correct |
30 ms |
47360 KB |
Output is correct |
25 |
Correct |
30 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47356 KB |
Output is correct |
27 |
Correct |
48 ms |
49128 KB |
Output is correct |
28 |
Correct |
46 ms |
48916 KB |
Output is correct |
29 |
Correct |
48 ms |
49016 KB |
Output is correct |
30 |
Correct |
53 ms |
49016 KB |
Output is correct |
31 |
Correct |
55 ms |
49016 KB |
Output is correct |
32 |
Correct |
52 ms |
48956 KB |
Output is correct |
33 |
Correct |
54 ms |
49016 KB |
Output is correct |
34 |
Correct |
56 ms |
49144 KB |
Output is correct |
35 |
Correct |
56 ms |
49144 KB |
Output is correct |
36 |
Correct |
52 ms |
49144 KB |
Output is correct |
37 |
Correct |
52 ms |
49144 KB |
Output is correct |
38 |
Correct |
52 ms |
49152 KB |
Output is correct |
39 |
Correct |
52 ms |
49144 KB |
Output is correct |
40 |
Correct |
52 ms |
49388 KB |
Output is correct |
41 |
Correct |
53 ms |
49400 KB |
Output is correct |
42 |
Correct |
55 ms |
49272 KB |
Output is correct |
43 |
Correct |
52 ms |
49400 KB |
Output is correct |
44 |
Correct |
53 ms |
49400 KB |
Output is correct |
45 |
Correct |
53 ms |
49400 KB |
Output is correct |
46 |
Correct |
53 ms |
49272 KB |
Output is correct |
47 |
Correct |
52 ms |
49400 KB |
Output is correct |
48 |
Correct |
304 ms |
68932 KB |
Output is correct |
49 |
Correct |
309 ms |
69244 KB |
Output is correct |
50 |
Correct |
303 ms |
68984 KB |
Output is correct |
51 |
Correct |
281 ms |
68600 KB |
Output is correct |
52 |
Correct |
255 ms |
65784 KB |
Output is correct |
53 |
Correct |
291 ms |
67320 KB |
Output is correct |
54 |
Correct |
289 ms |
65400 KB |
Output is correct |
55 |
Correct |
282 ms |
65020 KB |
Output is correct |
56 |
Correct |
286 ms |
64504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47280 KB |
Output is correct |
2 |
Correct |
31 ms |
47360 KB |
Output is correct |
3 |
Correct |
30 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
32 ms |
47352 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
31 ms |
47352 KB |
Output is correct |
10 |
Correct |
30 ms |
47360 KB |
Output is correct |
11 |
Correct |
34 ms |
47360 KB |
Output is correct |
12 |
Correct |
31 ms |
47360 KB |
Output is correct |
13 |
Correct |
32 ms |
47360 KB |
Output is correct |
14 |
Correct |
35 ms |
47352 KB |
Output is correct |
15 |
Correct |
34 ms |
47264 KB |
Output is correct |
16 |
Correct |
34 ms |
47352 KB |
Output is correct |
17 |
Correct |
35 ms |
47352 KB |
Output is correct |
18 |
Correct |
31 ms |
47360 KB |
Output is correct |
19 |
Correct |
30 ms |
47352 KB |
Output is correct |
20 |
Correct |
35 ms |
47352 KB |
Output is correct |
21 |
Correct |
31 ms |
47352 KB |
Output is correct |
22 |
Correct |
32 ms |
47364 KB |
Output is correct |
23 |
Correct |
33 ms |
47352 KB |
Output is correct |
24 |
Correct |
30 ms |
47360 KB |
Output is correct |
25 |
Correct |
30 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47356 KB |
Output is correct |
27 |
Correct |
48 ms |
49128 KB |
Output is correct |
28 |
Correct |
46 ms |
48916 KB |
Output is correct |
29 |
Correct |
48 ms |
49016 KB |
Output is correct |
30 |
Correct |
53 ms |
49016 KB |
Output is correct |
31 |
Correct |
55 ms |
49016 KB |
Output is correct |
32 |
Correct |
52 ms |
48956 KB |
Output is correct |
33 |
Correct |
54 ms |
49016 KB |
Output is correct |
34 |
Correct |
56 ms |
49144 KB |
Output is correct |
35 |
Correct |
56 ms |
49144 KB |
Output is correct |
36 |
Correct |
52 ms |
49144 KB |
Output is correct |
37 |
Correct |
52 ms |
49144 KB |
Output is correct |
38 |
Correct |
52 ms |
49152 KB |
Output is correct |
39 |
Correct |
52 ms |
49144 KB |
Output is correct |
40 |
Correct |
52 ms |
49388 KB |
Output is correct |
41 |
Correct |
53 ms |
49400 KB |
Output is correct |
42 |
Correct |
55 ms |
49272 KB |
Output is correct |
43 |
Correct |
52 ms |
49400 KB |
Output is correct |
44 |
Correct |
53 ms |
49400 KB |
Output is correct |
45 |
Correct |
53 ms |
49400 KB |
Output is correct |
46 |
Correct |
53 ms |
49272 KB |
Output is correct |
47 |
Correct |
52 ms |
49400 KB |
Output is correct |
48 |
Correct |
304 ms |
68932 KB |
Output is correct |
49 |
Correct |
309 ms |
69244 KB |
Output is correct |
50 |
Correct |
303 ms |
68984 KB |
Output is correct |
51 |
Correct |
281 ms |
68600 KB |
Output is correct |
52 |
Correct |
255 ms |
65784 KB |
Output is correct |
53 |
Correct |
291 ms |
67320 KB |
Output is correct |
54 |
Correct |
289 ms |
65400 KB |
Output is correct |
55 |
Correct |
282 ms |
65020 KB |
Output is correct |
56 |
Correct |
286 ms |
64504 KB |
Output is correct |
57 |
Correct |
1830 ms |
155136 KB |
Output is correct |
58 |
Correct |
1495 ms |
116216 KB |
Output is correct |
59 |
Correct |
1490 ms |
115960 KB |
Output is correct |
60 |
Correct |
1608 ms |
125816 KB |
Output is correct |
61 |
Correct |
1594 ms |
126200 KB |
Output is correct |
62 |
Correct |
820 ms |
93052 KB |
Output is correct |
63 |
Correct |
1125 ms |
103928 KB |
Output is correct |
64 |
Correct |
984 ms |
97272 KB |
Output is correct |
65 |
Correct |
571 ms |
79832 KB |
Output is correct |