Submission #837550

# Submission time Handle Problem Language Result Execution time Memory
837550 2023-08-25T12:12:09 Z Liudas Rope (JOI17_rope) C++17
80 / 100
2500 ms 170760 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(){
	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 << endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8404 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 3 ms 8404 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 3 ms 8404 KB Output is correct
15 Correct 3 ms 8404 KB Output is correct
16 Correct 3 ms 8404 KB Output is correct
17 Correct 3 ms 8404 KB Output is correct
18 Correct 3 ms 8404 KB Output is correct
19 Correct 5 ms 8404 KB Output is correct
20 Correct 3 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 3 ms 8404 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 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 8404 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 3 ms 8404 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 3 ms 8404 KB Output is correct
15 Correct 3 ms 8404 KB Output is correct
16 Correct 3 ms 8404 KB Output is correct
17 Correct 3 ms 8404 KB Output is correct
18 Correct 3 ms 8404 KB Output is correct
19 Correct 5 ms 8404 KB Output is correct
20 Correct 3 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 3 ms 8404 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 55 ms 10136 KB Output is correct
28 Correct 43 ms 9812 KB Output is correct
29 Correct 49 ms 9928 KB Output is correct
30 Correct 44 ms 9616 KB Output is correct
31 Correct 49 ms 10068 KB Output is correct
32 Correct 43 ms 9848 KB Output is correct
33 Correct 53 ms 10000 KB Output is correct
34 Correct 46 ms 9520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8404 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 3 ms 8404 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 3 ms 8404 KB Output is correct
15 Correct 3 ms 8404 KB Output is correct
16 Correct 3 ms 8404 KB Output is correct
17 Correct 3 ms 8404 KB Output is correct
18 Correct 3 ms 8404 KB Output is correct
19 Correct 5 ms 8404 KB Output is correct
20 Correct 3 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 3 ms 8404 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 55 ms 10136 KB Output is correct
28 Correct 43 ms 9812 KB Output is correct
29 Correct 49 ms 9928 KB Output is correct
30 Correct 44 ms 9616 KB Output is correct
31 Correct 49 ms 10068 KB Output is correct
32 Correct 43 ms 9848 KB Output is correct
33 Correct 53 ms 10000 KB Output is correct
34 Correct 46 ms 9520 KB Output is correct
35 Correct 65 ms 10076 KB Output is correct
36 Correct 74 ms 10148 KB Output is correct
37 Correct 65 ms 9996 KB Output is correct
38 Correct 67 ms 10012 KB Output is correct
39 Correct 67 ms 10060 KB Output is correct
40 Correct 56 ms 10196 KB Output is correct
41 Correct 55 ms 10164 KB Output is correct
42 Correct 57 ms 10088 KB Output is correct
43 Correct 55 ms 10208 KB Output is correct
44 Correct 56 ms 10292 KB Output is correct
45 Correct 57 ms 10236 KB Output is correct
46 Correct 53 ms 10060 KB Output is correct
47 Correct 52 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 8404 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 3 ms 8404 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 3 ms 8404 KB Output is correct
15 Correct 3 ms 8404 KB Output is correct
16 Correct 3 ms 8404 KB Output is correct
17 Correct 3 ms 8404 KB Output is correct
18 Correct 3 ms 8404 KB Output is correct
19 Correct 5 ms 8404 KB Output is correct
20 Correct 3 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 3 ms 8404 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 55 ms 10136 KB Output is correct
28 Correct 43 ms 9812 KB Output is correct
29 Correct 49 ms 9928 KB Output is correct
30 Correct 44 ms 9616 KB Output is correct
31 Correct 49 ms 10068 KB Output is correct
32 Correct 43 ms 9848 KB Output is correct
33 Correct 53 ms 10000 KB Output is correct
34 Correct 46 ms 9520 KB Output is correct
35 Correct 65 ms 10076 KB Output is correct
36 Correct 74 ms 10148 KB Output is correct
37 Correct 65 ms 9996 KB Output is correct
38 Correct 67 ms 10012 KB Output is correct
39 Correct 67 ms 10060 KB Output is correct
40 Correct 56 ms 10196 KB Output is correct
41 Correct 55 ms 10164 KB Output is correct
42 Correct 57 ms 10088 KB Output is correct
43 Correct 55 ms 10208 KB Output is correct
44 Correct 56 ms 10292 KB Output is correct
45 Correct 57 ms 10236 KB Output is correct
46 Correct 53 ms 10060 KB Output is correct
47 Correct 52 ms 10196 KB Output is correct
48 Correct 678 ms 25896 KB Output is correct
49 Correct 662 ms 25880 KB Output is correct
50 Correct 658 ms 25896 KB Output is correct
51 Correct 625 ms 25756 KB Output is correct
52 Correct 606 ms 23584 KB Output is correct
53 Correct 550 ms 24192 KB Output is correct
54 Correct 507 ms 22292 KB Output is correct
55 Correct 523 ms 21952 KB Output is correct
56 Correct 483 ms 21380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 3 ms 8404 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 3 ms 8404 KB Output is correct
9 Correct 3 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 3 ms 8404 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 3 ms 8404 KB Output is correct
15 Correct 3 ms 8404 KB Output is correct
16 Correct 3 ms 8404 KB Output is correct
17 Correct 3 ms 8404 KB Output is correct
18 Correct 3 ms 8404 KB Output is correct
19 Correct 5 ms 8404 KB Output is correct
20 Correct 3 ms 8404 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 3 ms 8404 KB Output is correct
23 Correct 4 ms 8404 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 3 ms 8404 KB Output is correct
26 Correct 3 ms 8404 KB Output is correct
27 Correct 55 ms 10136 KB Output is correct
28 Correct 43 ms 9812 KB Output is correct
29 Correct 49 ms 9928 KB Output is correct
30 Correct 44 ms 9616 KB Output is correct
31 Correct 49 ms 10068 KB Output is correct
32 Correct 43 ms 9848 KB Output is correct
33 Correct 53 ms 10000 KB Output is correct
34 Correct 46 ms 9520 KB Output is correct
35 Correct 65 ms 10076 KB Output is correct
36 Correct 74 ms 10148 KB Output is correct
37 Correct 65 ms 9996 KB Output is correct
38 Correct 67 ms 10012 KB Output is correct
39 Correct 67 ms 10060 KB Output is correct
40 Correct 56 ms 10196 KB Output is correct
41 Correct 55 ms 10164 KB Output is correct
42 Correct 57 ms 10088 KB Output is correct
43 Correct 55 ms 10208 KB Output is correct
44 Correct 56 ms 10292 KB Output is correct
45 Correct 57 ms 10236 KB Output is correct
46 Correct 53 ms 10060 KB Output is correct
47 Correct 52 ms 10196 KB Output is correct
48 Correct 678 ms 25896 KB Output is correct
49 Correct 662 ms 25880 KB Output is correct
50 Correct 658 ms 25896 KB Output is correct
51 Correct 625 ms 25756 KB Output is correct
52 Correct 606 ms 23584 KB Output is correct
53 Correct 550 ms 24192 KB Output is correct
54 Correct 507 ms 22292 KB Output is correct
55 Correct 523 ms 21952 KB Output is correct
56 Correct 483 ms 21380 KB Output is correct
57 Execution timed out 2564 ms 170760 KB Time limit exceeded
58 Halted 0 ms 0 KB -