Submission #1043883

# Submission time Handle Problem Language Result Execution time Memory
1043883 2024-08-05T02:50:49 Z juicy Rope (JOI17_rope) C++17
100 / 100
1307 ms 92184 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e6 + 5;

int n, m;
int c[N], res[N], cnt[N], s[4 * N];
vector<int> g[N];

void bld(int id = 1, int l = 1, int r = m) {
  if (l == r) {
    s[id] = cnt[l];
    return;
  }
  int md = (l + r) / 2;
  bld(id * 2, l, md);
  bld(id * 2 + 1, md + 1, r);
  s[id] = max(s[id * 2], s[id * 2 + 1]); 
}

void upd(int i, int x, int id = 1, int l = 1, int r = m) {
  if (l == r) {
    s[id] += x;
    return;
  }
  int md = (l + r) / 2;
  if (i <= md) {
    upd(i, x, id * 2, l, md);
  } else {
    upd(i, x, id * 2 + 1, md + 1, r);
  }
  s[id] = max(s[id * 2], s[id * 2 + 1]);
}

void add(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
} 

void solve(int p) {
  for (int i = 1; i <= m; ++i) {
    g[i].clear();
  }
  bld();
  for (int i = p; i + 1 <= n; i += 2) {
    if (c[i] != c[i + 1]) {
      add(c[i], c[i + 1]);
    }
  }
  for (int i = 1; i <= m; ++i) {
    upd(i, -cnt[i]);
    for (int j : g[i]) {
      upd(j, -1);
    }
    res[i] = max(res[i], cnt[i] + s[1]);
    for (int j : g[i]) {
      upd(j, 1);
    }
    upd(i, cnt[i]);
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    ++cnt[c[i]];
  }
  solve(1);
  solve(2);
  for (int i = 1; i <= m; ++i) {
    cout << n - res[i] << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29276 KB Output is correct
2 Correct 4 ms 29276 KB Output is correct
3 Correct 4 ms 29276 KB Output is correct
4 Correct 4 ms 29276 KB Output is correct
5 Correct 4 ms 29276 KB Output is correct
6 Correct 4 ms 29276 KB Output is correct
7 Correct 3 ms 29276 KB Output is correct
8 Correct 4 ms 29276 KB Output is correct
9 Correct 3 ms 29276 KB Output is correct
10 Correct 4 ms 29276 KB Output is correct
11 Correct 4 ms 29276 KB Output is correct
12 Correct 4 ms 29360 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 3 ms 29276 KB Output is correct
16 Correct 3 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 4 ms 29276 KB Output is correct
21 Correct 4 ms 29276 KB Output is correct
22 Correct 4 ms 29276 KB Output is correct
23 Correct 4 ms 29276 KB Output is correct
24 Correct 4 ms 29276 KB Output is correct
25 Correct 4 ms 29276 KB Output is correct
26 Correct 4 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29276 KB Output is correct
2 Correct 4 ms 29276 KB Output is correct
3 Correct 4 ms 29276 KB Output is correct
4 Correct 4 ms 29276 KB Output is correct
5 Correct 4 ms 29276 KB Output is correct
6 Correct 4 ms 29276 KB Output is correct
7 Correct 3 ms 29276 KB Output is correct
8 Correct 4 ms 29276 KB Output is correct
9 Correct 3 ms 29276 KB Output is correct
10 Correct 4 ms 29276 KB Output is correct
11 Correct 4 ms 29276 KB Output is correct
12 Correct 4 ms 29360 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 3 ms 29276 KB Output is correct
16 Correct 3 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 4 ms 29276 KB Output is correct
21 Correct 4 ms 29276 KB Output is correct
22 Correct 4 ms 29276 KB Output is correct
23 Correct 4 ms 29276 KB Output is correct
24 Correct 4 ms 29276 KB Output is correct
25 Correct 4 ms 29276 KB Output is correct
26 Correct 4 ms 29276 KB Output is correct
27 Correct 15 ms 30044 KB Output is correct
28 Correct 11 ms 30044 KB Output is correct
29 Correct 13 ms 30140 KB Output is correct
30 Correct 11 ms 29788 KB Output is correct
31 Correct 14 ms 30044 KB Output is correct
32 Correct 10 ms 30084 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 11 ms 29788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29276 KB Output is correct
2 Correct 4 ms 29276 KB Output is correct
3 Correct 4 ms 29276 KB Output is correct
4 Correct 4 ms 29276 KB Output is correct
5 Correct 4 ms 29276 KB Output is correct
6 Correct 4 ms 29276 KB Output is correct
7 Correct 3 ms 29276 KB Output is correct
8 Correct 4 ms 29276 KB Output is correct
9 Correct 3 ms 29276 KB Output is correct
10 Correct 4 ms 29276 KB Output is correct
11 Correct 4 ms 29276 KB Output is correct
12 Correct 4 ms 29360 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 3 ms 29276 KB Output is correct
16 Correct 3 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 4 ms 29276 KB Output is correct
21 Correct 4 ms 29276 KB Output is correct
22 Correct 4 ms 29276 KB Output is correct
23 Correct 4 ms 29276 KB Output is correct
24 Correct 4 ms 29276 KB Output is correct
25 Correct 4 ms 29276 KB Output is correct
26 Correct 4 ms 29276 KB Output is correct
27 Correct 15 ms 30044 KB Output is correct
28 Correct 11 ms 30044 KB Output is correct
29 Correct 13 ms 30140 KB Output is correct
30 Correct 11 ms 29788 KB Output is correct
31 Correct 14 ms 30044 KB Output is correct
32 Correct 10 ms 30084 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 11 ms 29788 KB Output is correct
35 Correct 25 ms 30300 KB Output is correct
36 Correct 25 ms 30300 KB Output is correct
37 Correct 25 ms 30300 KB Output is correct
38 Correct 25 ms 30300 KB Output is correct
39 Correct 25 ms 30300 KB Output is correct
40 Correct 20 ms 30300 KB Output is correct
41 Correct 20 ms 30404 KB Output is correct
42 Correct 20 ms 30384 KB Output is correct
43 Correct 19 ms 30300 KB Output is correct
44 Correct 25 ms 30400 KB Output is correct
45 Correct 25 ms 30300 KB Output is correct
46 Correct 20 ms 30300 KB Output is correct
47 Correct 19 ms 30300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29276 KB Output is correct
2 Correct 4 ms 29276 KB Output is correct
3 Correct 4 ms 29276 KB Output is correct
4 Correct 4 ms 29276 KB Output is correct
5 Correct 4 ms 29276 KB Output is correct
6 Correct 4 ms 29276 KB Output is correct
7 Correct 3 ms 29276 KB Output is correct
8 Correct 4 ms 29276 KB Output is correct
9 Correct 3 ms 29276 KB Output is correct
10 Correct 4 ms 29276 KB Output is correct
11 Correct 4 ms 29276 KB Output is correct
12 Correct 4 ms 29360 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 3 ms 29276 KB Output is correct
16 Correct 3 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 4 ms 29276 KB Output is correct
21 Correct 4 ms 29276 KB Output is correct
22 Correct 4 ms 29276 KB Output is correct
23 Correct 4 ms 29276 KB Output is correct
24 Correct 4 ms 29276 KB Output is correct
25 Correct 4 ms 29276 KB Output is correct
26 Correct 4 ms 29276 KB Output is correct
27 Correct 15 ms 30044 KB Output is correct
28 Correct 11 ms 30044 KB Output is correct
29 Correct 13 ms 30140 KB Output is correct
30 Correct 11 ms 29788 KB Output is correct
31 Correct 14 ms 30044 KB Output is correct
32 Correct 10 ms 30084 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 11 ms 29788 KB Output is correct
35 Correct 25 ms 30300 KB Output is correct
36 Correct 25 ms 30300 KB Output is correct
37 Correct 25 ms 30300 KB Output is correct
38 Correct 25 ms 30300 KB Output is correct
39 Correct 25 ms 30300 KB Output is correct
40 Correct 20 ms 30300 KB Output is correct
41 Correct 20 ms 30404 KB Output is correct
42 Correct 20 ms 30384 KB Output is correct
43 Correct 19 ms 30300 KB Output is correct
44 Correct 25 ms 30400 KB Output is correct
45 Correct 25 ms 30300 KB Output is correct
46 Correct 20 ms 30300 KB Output is correct
47 Correct 19 ms 30300 KB Output is correct
48 Correct 296 ms 44076 KB Output is correct
49 Correct 295 ms 43984 KB Output is correct
50 Correct 286 ms 43860 KB Output is correct
51 Correct 275 ms 43608 KB Output is correct
52 Correct 272 ms 42324 KB Output is correct
53 Correct 224 ms 43092 KB Output is correct
54 Correct 224 ms 42068 KB Output is correct
55 Correct 206 ms 42048 KB Output is correct
56 Correct 204 ms 41556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29276 KB Output is correct
2 Correct 4 ms 29276 KB Output is correct
3 Correct 4 ms 29276 KB Output is correct
4 Correct 4 ms 29276 KB Output is correct
5 Correct 4 ms 29276 KB Output is correct
6 Correct 4 ms 29276 KB Output is correct
7 Correct 3 ms 29276 KB Output is correct
8 Correct 4 ms 29276 KB Output is correct
9 Correct 3 ms 29276 KB Output is correct
10 Correct 4 ms 29276 KB Output is correct
11 Correct 4 ms 29276 KB Output is correct
12 Correct 4 ms 29360 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 3 ms 29276 KB Output is correct
16 Correct 3 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 4 ms 29276 KB Output is correct
21 Correct 4 ms 29276 KB Output is correct
22 Correct 4 ms 29276 KB Output is correct
23 Correct 4 ms 29276 KB Output is correct
24 Correct 4 ms 29276 KB Output is correct
25 Correct 4 ms 29276 KB Output is correct
26 Correct 4 ms 29276 KB Output is correct
27 Correct 15 ms 30044 KB Output is correct
28 Correct 11 ms 30044 KB Output is correct
29 Correct 13 ms 30140 KB Output is correct
30 Correct 11 ms 29788 KB Output is correct
31 Correct 14 ms 30044 KB Output is correct
32 Correct 10 ms 30084 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 11 ms 29788 KB Output is correct
35 Correct 25 ms 30300 KB Output is correct
36 Correct 25 ms 30300 KB Output is correct
37 Correct 25 ms 30300 KB Output is correct
38 Correct 25 ms 30300 KB Output is correct
39 Correct 25 ms 30300 KB Output is correct
40 Correct 20 ms 30300 KB Output is correct
41 Correct 20 ms 30404 KB Output is correct
42 Correct 20 ms 30384 KB Output is correct
43 Correct 19 ms 30300 KB Output is correct
44 Correct 25 ms 30400 KB Output is correct
45 Correct 25 ms 30300 KB Output is correct
46 Correct 20 ms 30300 KB Output is correct
47 Correct 19 ms 30300 KB Output is correct
48 Correct 296 ms 44076 KB Output is correct
49 Correct 295 ms 43984 KB Output is correct
50 Correct 286 ms 43860 KB Output is correct
51 Correct 275 ms 43608 KB Output is correct
52 Correct 272 ms 42324 KB Output is correct
53 Correct 224 ms 43092 KB Output is correct
54 Correct 224 ms 42068 KB Output is correct
55 Correct 206 ms 42048 KB Output is correct
56 Correct 204 ms 41556 KB Output is correct
57 Correct 1307 ms 92184 KB Output is correct
58 Correct 1006 ms 76848 KB Output is correct
59 Correct 969 ms 76884 KB Output is correct
60 Correct 1032 ms 80592 KB Output is correct
61 Correct 1041 ms 80628 KB Output is correct
62 Correct 549 ms 61268 KB Output is correct
63 Correct 744 ms 65752 KB Output is correct
64 Correct 626 ms 63064 KB Output is correct
65 Correct 434 ms 53360 KB Output is correct