#include <bits/stdc++.h>
using namespace std;
int tree[1048576 * 2] = {0};
int N = 1048576;
void update(int pos, int val){
int head = N + pos;
tree[head] += val;
head /= 2;
while(head){
tree[head] = max(tree[head * 2 + 1], tree[head * 2]);
head /= 2;
}
}
int arr[1000050];
int main(){
int N, M;
cin >> N >> M;
for(int i = 0; i < N; i ++){
cin >> arr[i];
arr[i]--;
}
vector<vector<vector<int>>> brr(M + 5, vector<vector<int>>(2));
vector<int> counts(M + 5);
for(int i = 0; i < N; i ++){
for(int j = 0; j < 2; j ++){
int pi = i + 1 - (i + j) % 2 * 2;
if(pi > -1 && pi < N && arr[pi] != arr[i]){
brr[arr[i]][j].push_back(arr[pi]);
}
}
counts[arr[i]] ++;
update(arr[i], 1);
}
for(int i = 0; i < M; i ++){
update(i, -counts[i]);
int ans = N;
for(int j = 0; j < 2; j ++){
for(int &k : brr[i][j])update(k, -1);
ans = min(ans, N-tree[1]-counts[i]);
for(int &k : brr[i][j])update(k, 1);
}
update(i, counts[i]);
cout << ans << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
45 ms |
1912 KB |
Output is correct |
28 |
Correct |
51 ms |
1736 KB |
Output is correct |
29 |
Correct |
53 ms |
1892 KB |
Output is correct |
30 |
Correct |
51 ms |
1528 KB |
Output is correct |
31 |
Correct |
48 ms |
1980 KB |
Output is correct |
32 |
Correct |
51 ms |
1820 KB |
Output is correct |
33 |
Correct |
53 ms |
1852 KB |
Output is correct |
34 |
Correct |
54 ms |
1420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
45 ms |
1912 KB |
Output is correct |
28 |
Correct |
51 ms |
1736 KB |
Output is correct |
29 |
Correct |
53 ms |
1892 KB |
Output is correct |
30 |
Correct |
51 ms |
1528 KB |
Output is correct |
31 |
Correct |
48 ms |
1980 KB |
Output is correct |
32 |
Correct |
51 ms |
1820 KB |
Output is correct |
33 |
Correct |
53 ms |
1852 KB |
Output is correct |
34 |
Correct |
54 ms |
1420 KB |
Output is correct |
35 |
Correct |
41 ms |
1832 KB |
Output is correct |
36 |
Correct |
42 ms |
1876 KB |
Output is correct |
37 |
Correct |
40 ms |
1860 KB |
Output is correct |
38 |
Correct |
49 ms |
1896 KB |
Output is correct |
39 |
Correct |
44 ms |
1840 KB |
Output is correct |
40 |
Correct |
40 ms |
2036 KB |
Output is correct |
41 |
Correct |
41 ms |
2132 KB |
Output is correct |
42 |
Correct |
41 ms |
2064 KB |
Output is correct |
43 |
Correct |
41 ms |
2068 KB |
Output is correct |
44 |
Correct |
41 ms |
2020 KB |
Output is correct |
45 |
Correct |
42 ms |
1996 KB |
Output is correct |
46 |
Correct |
46 ms |
2004 KB |
Output is correct |
47 |
Correct |
52 ms |
2092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
45 ms |
1912 KB |
Output is correct |
28 |
Correct |
51 ms |
1736 KB |
Output is correct |
29 |
Correct |
53 ms |
1892 KB |
Output is correct |
30 |
Correct |
51 ms |
1528 KB |
Output is correct |
31 |
Correct |
48 ms |
1980 KB |
Output is correct |
32 |
Correct |
51 ms |
1820 KB |
Output is correct |
33 |
Correct |
53 ms |
1852 KB |
Output is correct |
34 |
Correct |
54 ms |
1420 KB |
Output is correct |
35 |
Correct |
41 ms |
1832 KB |
Output is correct |
36 |
Correct |
42 ms |
1876 KB |
Output is correct |
37 |
Correct |
40 ms |
1860 KB |
Output is correct |
38 |
Correct |
49 ms |
1896 KB |
Output is correct |
39 |
Correct |
44 ms |
1840 KB |
Output is correct |
40 |
Correct |
40 ms |
2036 KB |
Output is correct |
41 |
Correct |
41 ms |
2132 KB |
Output is correct |
42 |
Correct |
41 ms |
2064 KB |
Output is correct |
43 |
Correct |
41 ms |
2068 KB |
Output is correct |
44 |
Correct |
41 ms |
2020 KB |
Output is correct |
45 |
Correct |
42 ms |
1996 KB |
Output is correct |
46 |
Correct |
46 ms |
2004 KB |
Output is correct |
47 |
Correct |
52 ms |
2092 KB |
Output is correct |
48 |
Correct |
444 ms |
17780 KB |
Output is correct |
49 |
Correct |
444 ms |
17716 KB |
Output is correct |
50 |
Correct |
434 ms |
17792 KB |
Output is correct |
51 |
Correct |
429 ms |
17632 KB |
Output is correct |
52 |
Correct |
398 ms |
15460 KB |
Output is correct |
53 |
Correct |
416 ms |
16192 KB |
Output is correct |
54 |
Correct |
418 ms |
14172 KB |
Output is correct |
55 |
Correct |
426 ms |
13852 KB |
Output is correct |
56 |
Correct |
408 ms |
13280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
45 ms |
1912 KB |
Output is correct |
28 |
Correct |
51 ms |
1736 KB |
Output is correct |
29 |
Correct |
53 ms |
1892 KB |
Output is correct |
30 |
Correct |
51 ms |
1528 KB |
Output is correct |
31 |
Correct |
48 ms |
1980 KB |
Output is correct |
32 |
Correct |
51 ms |
1820 KB |
Output is correct |
33 |
Correct |
53 ms |
1852 KB |
Output is correct |
34 |
Correct |
54 ms |
1420 KB |
Output is correct |
35 |
Correct |
41 ms |
1832 KB |
Output is correct |
36 |
Correct |
42 ms |
1876 KB |
Output is correct |
37 |
Correct |
40 ms |
1860 KB |
Output is correct |
38 |
Correct |
49 ms |
1896 KB |
Output is correct |
39 |
Correct |
44 ms |
1840 KB |
Output is correct |
40 |
Correct |
40 ms |
2036 KB |
Output is correct |
41 |
Correct |
41 ms |
2132 KB |
Output is correct |
42 |
Correct |
41 ms |
2064 KB |
Output is correct |
43 |
Correct |
41 ms |
2068 KB |
Output is correct |
44 |
Correct |
41 ms |
2020 KB |
Output is correct |
45 |
Correct |
42 ms |
1996 KB |
Output is correct |
46 |
Correct |
46 ms |
2004 KB |
Output is correct |
47 |
Correct |
52 ms |
2092 KB |
Output is correct |
48 |
Correct |
444 ms |
17780 KB |
Output is correct |
49 |
Correct |
444 ms |
17716 KB |
Output is correct |
50 |
Correct |
434 ms |
17792 KB |
Output is correct |
51 |
Correct |
429 ms |
17632 KB |
Output is correct |
52 |
Correct |
398 ms |
15460 KB |
Output is correct |
53 |
Correct |
416 ms |
16192 KB |
Output is correct |
54 |
Correct |
418 ms |
14172 KB |
Output is correct |
55 |
Correct |
426 ms |
13852 KB |
Output is correct |
56 |
Correct |
408 ms |
13280 KB |
Output is correct |
57 |
Execution timed out |
2540 ms |
171672 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |