Submission #837732

# Submission time Handle Problem Language Result Execution time Memory
837732 2023-08-25T14:55:30 Z Liudas Rope (JOI17_rope) C++17
100 / 100
1841 ms 172232 KB
#include <bits/stdc++.h>
using namespace std;
class segment_tree{
public:
int tree[1048576 * 2] = {0};
int N = 1048576;
void update(int head, int l, int r, int pos, int val){
	if(r - l == 1){
		tree[head] += val;
		return;
	}
	int mid = (l + r) / 2;
	if(pos < mid){
		update(head * 2 + 1, l, mid, pos, val);
	}
	else{
		update(head *2 + 2, mid, r, pos, val);
	}
	tree[head] = max(tree[head * 2 + 2], tree[head * 2 + 1]); 
}
void update(int pos, int val){
	update(0, 0, N, pos, val);
}
};
int arr[1000050];
int main(){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i ++){
		cin >> arr[i];
		arr[i]--;
	}
	segment_tree tree;
	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]] ++;
		tree.update(arr[i], 1);
	}
	for(int i = 0; i < M; i ++){
		tree.update(i, -counts[i]);
		int ans = N;
		for(int j = 0; j < 2; j ++){
			for(int &k : brr[i][j])tree.update(k, -1);
			ans = min(ans, N-tree.tree[0]-counts[i]);
			for(int &k : brr[i][j])tree.update(k, 1);
		}
		tree.update(i, counts[i]);
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8532 KB Output is correct
4 Correct 3 ms 8532 KB Output is correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 3 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 3 ms 8532 KB Output is correct
14 Correct 3 ms 8532 KB Output is correct
15 Correct 3 ms 8532 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 3 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 3 ms 8532 KB Output is correct
22 Correct 3 ms 8532 KB Output is correct
23 Correct 3 ms 8532 KB Output is correct
24 Correct 3 ms 8532 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8532 KB Output is correct
4 Correct 3 ms 8532 KB Output is correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 3 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 3 ms 8532 KB Output is correct
14 Correct 3 ms 8532 KB Output is correct
15 Correct 3 ms 8532 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 3 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 3 ms 8532 KB Output is correct
22 Correct 3 ms 8532 KB Output is correct
23 Correct 3 ms 8532 KB Output is correct
24 Correct 3 ms 8532 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 41 ms 10068 KB Output is correct
28 Correct 35 ms 9812 KB Output is correct
29 Correct 43 ms 10068 KB Output is correct
30 Correct 37 ms 9684 KB Output is correct
31 Correct 42 ms 10132 KB Output is correct
32 Correct 36 ms 9812 KB Output is correct
33 Correct 42 ms 9940 KB Output is correct
34 Correct 36 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8532 KB Output is correct
4 Correct 3 ms 8532 KB Output is correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 3 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 3 ms 8532 KB Output is correct
14 Correct 3 ms 8532 KB Output is correct
15 Correct 3 ms 8532 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 3 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 3 ms 8532 KB Output is correct
22 Correct 3 ms 8532 KB Output is correct
23 Correct 3 ms 8532 KB Output is correct
24 Correct 3 ms 8532 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 41 ms 10068 KB Output is correct
28 Correct 35 ms 9812 KB Output is correct
29 Correct 43 ms 10068 KB Output is correct
30 Correct 37 ms 9684 KB Output is correct
31 Correct 42 ms 10132 KB Output is correct
32 Correct 36 ms 9812 KB Output is correct
33 Correct 42 ms 9940 KB Output is correct
34 Correct 36 ms 9556 KB Output is correct
35 Correct 54 ms 10092 KB Output is correct
36 Correct 51 ms 10216 KB Output is correct
37 Correct 54 ms 10068 KB Output is correct
38 Correct 52 ms 10068 KB Output is correct
39 Correct 52 ms 10068 KB Output is correct
40 Correct 43 ms 10264 KB Output is correct
41 Correct 46 ms 10324 KB Output is correct
42 Correct 44 ms 10204 KB Output is correct
43 Correct 43 ms 10196 KB Output is correct
44 Correct 43 ms 10196 KB Output is correct
45 Correct 46 ms 10196 KB Output is correct
46 Correct 42 ms 10196 KB Output is correct
47 Correct 42 ms 10196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8532 KB Output is correct
4 Correct 3 ms 8532 KB Output is correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 3 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 3 ms 8532 KB Output is correct
14 Correct 3 ms 8532 KB Output is correct
15 Correct 3 ms 8532 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 3 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 3 ms 8532 KB Output is correct
22 Correct 3 ms 8532 KB Output is correct
23 Correct 3 ms 8532 KB Output is correct
24 Correct 3 ms 8532 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 41 ms 10068 KB Output is correct
28 Correct 35 ms 9812 KB Output is correct
29 Correct 43 ms 10068 KB Output is correct
30 Correct 37 ms 9684 KB Output is correct
31 Correct 42 ms 10132 KB Output is correct
32 Correct 36 ms 9812 KB Output is correct
33 Correct 42 ms 9940 KB Output is correct
34 Correct 36 ms 9556 KB Output is correct
35 Correct 54 ms 10092 KB Output is correct
36 Correct 51 ms 10216 KB Output is correct
37 Correct 54 ms 10068 KB Output is correct
38 Correct 52 ms 10068 KB Output is correct
39 Correct 52 ms 10068 KB Output is correct
40 Correct 43 ms 10264 KB Output is correct
41 Correct 46 ms 10324 KB Output is correct
42 Correct 44 ms 10204 KB Output is correct
43 Correct 43 ms 10196 KB Output is correct
44 Correct 43 ms 10196 KB Output is correct
45 Correct 46 ms 10196 KB Output is correct
46 Correct 42 ms 10196 KB Output is correct
47 Correct 42 ms 10196 KB Output is correct
48 Correct 541 ms 25952 KB Output is correct
49 Correct 560 ms 25892 KB Output is correct
50 Correct 542 ms 25928 KB Output is correct
51 Correct 530 ms 25756 KB Output is correct
52 Correct 525 ms 23604 KB Output is correct
53 Correct 435 ms 24316 KB Output is correct
54 Correct 403 ms 22316 KB Output is correct
55 Correct 390 ms 22016 KB Output is correct
56 Correct 357 ms 21356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8532 KB Output is correct
4 Correct 3 ms 8532 KB Output is correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 3 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 3 ms 8532 KB Output is correct
14 Correct 3 ms 8532 KB Output is correct
15 Correct 3 ms 8532 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8532 KB Output is correct
18 Correct 4 ms 8532 KB Output is correct
19 Correct 3 ms 8532 KB Output is correct
20 Correct 5 ms 8532 KB Output is correct
21 Correct 3 ms 8532 KB Output is correct
22 Correct 3 ms 8532 KB Output is correct
23 Correct 3 ms 8532 KB Output is correct
24 Correct 3 ms 8532 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 41 ms 10068 KB Output is correct
28 Correct 35 ms 9812 KB Output is correct
29 Correct 43 ms 10068 KB Output is correct
30 Correct 37 ms 9684 KB Output is correct
31 Correct 42 ms 10132 KB Output is correct
32 Correct 36 ms 9812 KB Output is correct
33 Correct 42 ms 9940 KB Output is correct
34 Correct 36 ms 9556 KB Output is correct
35 Correct 54 ms 10092 KB Output is correct
36 Correct 51 ms 10216 KB Output is correct
37 Correct 54 ms 10068 KB Output is correct
38 Correct 52 ms 10068 KB Output is correct
39 Correct 52 ms 10068 KB Output is correct
40 Correct 43 ms 10264 KB Output is correct
41 Correct 46 ms 10324 KB Output is correct
42 Correct 44 ms 10204 KB Output is correct
43 Correct 43 ms 10196 KB Output is correct
44 Correct 43 ms 10196 KB Output is correct
45 Correct 46 ms 10196 KB Output is correct
46 Correct 42 ms 10196 KB Output is correct
47 Correct 42 ms 10196 KB Output is correct
48 Correct 541 ms 25952 KB Output is correct
49 Correct 560 ms 25892 KB Output is correct
50 Correct 542 ms 25928 KB Output is correct
51 Correct 530 ms 25756 KB Output is correct
52 Correct 525 ms 23604 KB Output is correct
53 Correct 435 ms 24316 KB Output is correct
54 Correct 403 ms 22316 KB Output is correct
55 Correct 390 ms 22016 KB Output is correct
56 Correct 357 ms 21356 KB Output is correct
57 Correct 1841 ms 172232 KB Output is correct
58 Correct 1649 ms 108480 KB Output is correct
59 Correct 1636 ms 107896 KB Output is correct
60 Correct 1737 ms 124020 KB Output is correct
61 Correct 1751 ms 124324 KB Output is correct
62 Correct 845 ms 66332 KB Output is correct
63 Correct 1193 ms 84720 KB Output is correct
64 Correct 994 ms 73612 KB Output is correct
65 Correct 604 ms 44632 KB Output is correct