# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
837559 |
2023-08-25T12:15:25 Z |
Liudas |
Rope (JOI17_rope) |
C++17 |
|
1 ms |
720 KB |
#include <bits/stdc++.h>
using namespace std;
class segment_tree{
public:
int tree[50000] = {0};
int N = 50000;
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<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]] ++;
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(auto &[l, r]: brr[i][j])tree.update(l, -r);
ans = min(ans, N-tree.tree[0]-counts[i]);
for(auto &[l, r]: brr[i][j])tree.update(l, r);
}
tree.update(i, counts[i]);
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |