Submission #496080

# Submission time Handle Problem Language Result Execution time Memory
496080 2021-12-20T15:00:39 Z 600Mihnea Bubble Sort 2 (JOI18_bubblesort2) C++17
60 / 100
9000 ms 34248 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 7;
const int NAX = (int) 1e6 + 7;
int N;
int coef[NAX];
int value[NAX];
bool valid[NAX];

void add(int l, int r, int x) {
  for (int j = l; j <= r; j++) {
    value[j] += x;
  }
}

vector<int> innterCountScans(vector<ll> a, vector<int> pos, vector<ll> ChangeValue) {
  int n = (int) a.size();
  int q = (int) pos.size();

  for (int i = 0; i < n; i++) {
    a[i] = a[i] * (ll) (n + 1) + i;
  }


  for (int it = 0; it < q; it++) {
    ChangeValue[it] = ChangeValue[it] * (ll) (n + 1) + pos[it];
  }

  map<ll, int> mp;
  for (auto &x : a) {
    mp[x] = 0;
  }
  for (auto &x : ChangeValue) {
    mp[x] = 0;
  }

  {
    int ij = 0;
    for (auto &it : mp) {
      it.second = ++ij;
    }
    N = ij;
    assert(N <= n + q);
  }

  for (auto &x : a) {
    x = mp[x];
  }
  for (auto &x : ChangeValue) {
    x = mp[x];
  }

  for (int i = 1; i <= N; i++) {
    coef[i] = -INF;
  }
  add(1, N, -INF);


  for (int i = 0; i < n; i++) {
    valid[a[i]] = 1;
    add(a[i], a[i], i - coef[a[i]]);
    coef[a[i]] += i - coef[a[i]];
  }


  vector<int> sol;

  for (int it = 0; it < q; it++) {
    if (1) {
      valid[a[pos[it]]] = 0;
      add(a[pos[it]], a[pos[it]], -(coef[a[pos[it]]] + INF));
      coef[a[pos[it]]] += -(coef[a[pos[it]]] + INF);

      a[pos[it]] = ChangeValue[it];

      valid[a[pos[it]]] = 1;
      add(a[pos[it]], a[pos[it]], pos[it] - coef[a[pos[it]]]);
      coef[a[pos[it]]] += pos[it] - coef[a[pos[it]]];
    }

    int cnt = 0, MX = 0;

    for (int i = 1; i <= N; i++) {
      cnt += valid[i];
      MX = max(MX, coef[i] - cnt);

      assert(value[i] == coef[i]);
    }

    sol.push_back(MX + 1);
  }

  return sol;
}


vector<int> countScans(vector<int> a, vector<int> b, vector<int> c) {
  vector<ll> X, Z;
  for (auto &it : a) {
    X.push_back(it);
  }
  for (auto &it : c) {
    Z.push_back(it);
  }
  return innterCountScans(X, b, Z);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 11 ms 716 KB Output is correct
4 Correct 14 ms 712 KB Output is correct
5 Correct 11 ms 716 KB Output is correct
6 Correct 11 ms 708 KB Output is correct
7 Correct 12 ms 732 KB Output is correct
8 Correct 12 ms 724 KB Output is correct
9 Correct 12 ms 716 KB Output is correct
10 Correct 10 ms 676 KB Output is correct
11 Correct 10 ms 588 KB Output is correct
12 Correct 11 ms 688 KB Output is correct
13 Correct 9 ms 668 KB Output is correct
14 Correct 9 ms 660 KB Output is correct
15 Correct 10 ms 588 KB Output is correct
16 Correct 8 ms 656 KB Output is correct
17 Correct 8 ms 660 KB Output is correct
18 Correct 8 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 11 ms 716 KB Output is correct
4 Correct 14 ms 712 KB Output is correct
5 Correct 11 ms 716 KB Output is correct
6 Correct 11 ms 708 KB Output is correct
7 Correct 12 ms 732 KB Output is correct
8 Correct 12 ms 724 KB Output is correct
9 Correct 12 ms 716 KB Output is correct
10 Correct 10 ms 676 KB Output is correct
11 Correct 10 ms 588 KB Output is correct
12 Correct 11 ms 688 KB Output is correct
13 Correct 9 ms 668 KB Output is correct
14 Correct 9 ms 660 KB Output is correct
15 Correct 10 ms 588 KB Output is correct
16 Correct 8 ms 656 KB Output is correct
17 Correct 8 ms 660 KB Output is correct
18 Correct 8 ms 664 KB Output is correct
19 Correct 112 ms 1876 KB Output is correct
20 Correct 145 ms 1924 KB Output is correct
21 Correct 142 ms 1968 KB Output is correct
22 Correct 141 ms 1928 KB Output is correct
23 Correct 131 ms 1860 KB Output is correct
24 Correct 132 ms 1824 KB Output is correct
25 Correct 116 ms 1720 KB Output is correct
26 Correct 120 ms 1716 KB Output is correct
27 Correct 119 ms 1644 KB Output is correct
28 Correct 110 ms 1760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 3284 KB Output is correct
2 Correct 1688 ms 6892 KB Output is correct
3 Correct 5240 ms 10896 KB Output is correct
4 Correct 5170 ms 11460 KB Output is correct
5 Correct 5161 ms 11548 KB Output is correct
6 Correct 5091 ms 11408 KB Output is correct
7 Correct 5080 ms 11504 KB Output is correct
8 Correct 5150 ms 11596 KB Output is correct
9 Correct 5175 ms 11700 KB Output is correct
10 Correct 2843 ms 8372 KB Output is correct
11 Correct 2857 ms 8408 KB Output is correct
12 Correct 2857 ms 8456 KB Output is correct
13 Correct 2888 ms 8560 KB Output is correct
14 Correct 2902 ms 8692 KB Output is correct
15 Correct 2874 ms 8568 KB Output is correct
16 Correct 2870 ms 8584 KB Output is correct
17 Correct 2824 ms 8408 KB Output is correct
18 Correct 2917 ms 8552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 11 ms 716 KB Output is correct
4 Correct 14 ms 712 KB Output is correct
5 Correct 11 ms 716 KB Output is correct
6 Correct 11 ms 708 KB Output is correct
7 Correct 12 ms 732 KB Output is correct
8 Correct 12 ms 724 KB Output is correct
9 Correct 12 ms 716 KB Output is correct
10 Correct 10 ms 676 KB Output is correct
11 Correct 10 ms 588 KB Output is correct
12 Correct 11 ms 688 KB Output is correct
13 Correct 9 ms 668 KB Output is correct
14 Correct 9 ms 660 KB Output is correct
15 Correct 10 ms 588 KB Output is correct
16 Correct 8 ms 656 KB Output is correct
17 Correct 8 ms 660 KB Output is correct
18 Correct 8 ms 664 KB Output is correct
19 Correct 112 ms 1876 KB Output is correct
20 Correct 145 ms 1924 KB Output is correct
21 Correct 142 ms 1968 KB Output is correct
22 Correct 141 ms 1928 KB Output is correct
23 Correct 131 ms 1860 KB Output is correct
24 Correct 132 ms 1824 KB Output is correct
25 Correct 116 ms 1720 KB Output is correct
26 Correct 120 ms 1716 KB Output is correct
27 Correct 119 ms 1644 KB Output is correct
28 Correct 110 ms 1760 KB Output is correct
29 Correct 84 ms 3284 KB Output is correct
30 Correct 1688 ms 6892 KB Output is correct
31 Correct 5240 ms 10896 KB Output is correct
32 Correct 5170 ms 11460 KB Output is correct
33 Correct 5161 ms 11548 KB Output is correct
34 Correct 5091 ms 11408 KB Output is correct
35 Correct 5080 ms 11504 KB Output is correct
36 Correct 5150 ms 11596 KB Output is correct
37 Correct 5175 ms 11700 KB Output is correct
38 Correct 2843 ms 8372 KB Output is correct
39 Correct 2857 ms 8408 KB Output is correct
40 Correct 2857 ms 8456 KB Output is correct
41 Correct 2888 ms 8560 KB Output is correct
42 Correct 2902 ms 8692 KB Output is correct
43 Correct 2874 ms 8568 KB Output is correct
44 Correct 2870 ms 8584 KB Output is correct
45 Correct 2824 ms 8408 KB Output is correct
46 Correct 2917 ms 8552 KB Output is correct
47 Execution timed out 9012 ms 34248 KB Time limit exceeded
48 Halted 0 ms 0 KB -