# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20962 | kdh9949 | Rope (JOI17_rope) | C++14 | 1816 ms | 135280 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int sz = 1048576;
struct Seg{
int dat[2 * sz];
void upd(int x, int v){
x += sz - 1; dat[x] += v;
for(x /= 2; x; x /= 2) dat[x] = max(dat[2 * x], dat[2 * x + 1]);
}
int get(){ return dat[1]; }
} S;
int n, m, a[1000010], b[1000010][2], c[1000010];
vector<int> d[1000010][2];
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= n; i++){
for(int j = 0; j < 2; j++){
int nx = i + 1 - (i + j) % 2 * 2;
if(a[nx] && a[nx] != a[i]) d[a[i]][j].push_back(a[nx]);
}
S.upd(a[i], 1);
c[a[i]]++;
}
for(int i = 1; i <= m; i++){
S.upd(i, -c[i]);
int ans = n;
for(int j = 0; j < 2; j++){
for(auto &k : d[i][j]) S.upd(k, -1);
ans = min(ans, n - c[i] - S.get());
for(auto &k : d[i][j]) S.upd(k, 1);
}
S.upd(i, c[i]);
printf("%d\n", ans);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |