Submission #837568

# Submission time Handle Problem Language Result Execution time Memory
837568 2023-08-25T12:19:12 Z Liudas Rope (JOI17_rope) C++17
55 / 100
2500 ms 93504 KB
#include <bits/stdc++.h>
using namespace std;
int tree[1111111 * 2] = {0};
int N = 1111111;
class segment_tree{
public:
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(){
	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i ++){
		cin >> arr[i];
		arr[i]--;
	}
	segment_tree tre;
	vector<vector<map<int, int>>> brr(M + 5, vector<map<int, 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][arr[pi]]++;
			}
		}
		counts[arr[i]] ++;
		tre.update(arr[i], 1);
	}
	for(int i = 0; i < M; i ++){
		tre.update(i, -counts[i]);
		int ans = N;
		for(int j = 0; j < 2; j ++){
			for(auto &[l, r]: brr[i][j])tre.update(l, -r);
			ans = min(ans, N-tree[0]-counts[i]);
			for(auto &[l, r]: brr[i][j])tre.update(l, r);
		}
		tre.update(i, counts[i]);
		cout << ans << endl;
	}
}
# Verdict Execution time Memory 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 1 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory 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 1 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 22 ms 724 KB Output is correct
28 Correct 26 ms 844 KB Output is correct
29 Correct 21 ms 764 KB Output is correct
30 Correct 20 ms 768 KB Output is correct
31 Correct 22 ms 752 KB Output is correct
32 Correct 18 ms 660 KB Output is correct
33 Correct 23 ms 764 KB Output is correct
34 Correct 19 ms 692 KB Output is correct
# Verdict Execution time Memory 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 1 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 22 ms 724 KB Output is correct
28 Correct 26 ms 844 KB Output is correct
29 Correct 21 ms 764 KB Output is correct
30 Correct 20 ms 768 KB Output is correct
31 Correct 22 ms 752 KB Output is correct
32 Correct 18 ms 660 KB Output is correct
33 Correct 23 ms 764 KB Output is correct
34 Correct 19 ms 692 KB Output is correct
35 Correct 105 ms 8564 KB Output is correct
36 Correct 108 ms 8472 KB Output is correct
37 Correct 96 ms 8416 KB Output is correct
38 Correct 100 ms 8396 KB Output is correct
39 Correct 99 ms 8492 KB Output is correct
40 Correct 55 ms 4808 KB Output is correct
41 Correct 56 ms 4812 KB Output is correct
42 Correct 51 ms 3924 KB Output is correct
43 Correct 48 ms 3744 KB Output is correct
44 Correct 57 ms 4924 KB Output is correct
45 Correct 60 ms 4940 KB Output is correct
46 Correct 48 ms 4072 KB Output is correct
47 Correct 55 ms 3768 KB Output is correct
# Verdict Execution time Memory 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 1 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 22 ms 724 KB Output is correct
28 Correct 26 ms 844 KB Output is correct
29 Correct 21 ms 764 KB Output is correct
30 Correct 20 ms 768 KB Output is correct
31 Correct 22 ms 752 KB Output is correct
32 Correct 18 ms 660 KB Output is correct
33 Correct 23 ms 764 KB Output is correct
34 Correct 19 ms 692 KB Output is correct
35 Correct 105 ms 8564 KB Output is correct
36 Correct 108 ms 8472 KB Output is correct
37 Correct 96 ms 8416 KB Output is correct
38 Correct 100 ms 8396 KB Output is correct
39 Correct 99 ms 8492 KB Output is correct
40 Correct 55 ms 4808 KB Output is correct
41 Correct 56 ms 4812 KB Output is correct
42 Correct 51 ms 3924 KB Output is correct
43 Correct 48 ms 3744 KB Output is correct
44 Correct 57 ms 4924 KB Output is correct
45 Correct 60 ms 4940 KB Output is correct
46 Correct 48 ms 4072 KB Output is correct
47 Correct 55 ms 3768 KB Output is correct
48 Execution timed out 2569 ms 93504 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 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 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 356 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 22 ms 724 KB Output is correct
28 Correct 26 ms 844 KB Output is correct
29 Correct 21 ms 764 KB Output is correct
30 Correct 20 ms 768 KB Output is correct
31 Correct 22 ms 752 KB Output is correct
32 Correct 18 ms 660 KB Output is correct
33 Correct 23 ms 764 KB Output is correct
34 Correct 19 ms 692 KB Output is correct
35 Correct 105 ms 8564 KB Output is correct
36 Correct 108 ms 8472 KB Output is correct
37 Correct 96 ms 8416 KB Output is correct
38 Correct 100 ms 8396 KB Output is correct
39 Correct 99 ms 8492 KB Output is correct
40 Correct 55 ms 4808 KB Output is correct
41 Correct 56 ms 4812 KB Output is correct
42 Correct 51 ms 3924 KB Output is correct
43 Correct 48 ms 3744 KB Output is correct
44 Correct 57 ms 4924 KB Output is correct
45 Correct 60 ms 4940 KB Output is correct
46 Correct 48 ms 4072 KB Output is correct
47 Correct 55 ms 3768 KB Output is correct
48 Execution timed out 2569 ms 93504 KB Time limit exceeded
49 Halted 0 ms 0 KB -