Submission #496081

# Submission time Handle Problem Language Result Execution time Memory
496081 2021-12-20T15:04:49 Z 600Mihnea Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
9000 ms 11136 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;
  }
}

int getMax() {
  int sol = 0;
  for (int i = 1; i <= N; i++) {
    sol = max(sol, value[i]);
  }
  return sol;
}

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]];
    add(a[i], N, -1);
  }


  vector<int> sol;

  for (int it = 0; it < q; it++) {
    if (1) {
      valid[a[pos[it]]] = 0;
      add(a[pos[it]], N, +1);
      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]], N, -1);
      add(a[pos[it]], a[pos[it]], pos[it] - coef[a[pos[it]]]);
      coef[a[pos[it]]] += pos[it] - coef[a[pos[it]]];
    }

    sol.push_back(getMax() + 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 5 ms 460 KB Output is correct
3 Correct 19 ms 716 KB Output is correct
4 Correct 20 ms 732 KB Output is correct
5 Correct 19 ms 724 KB Output is correct
6 Correct 17 ms 712 KB Output is correct
7 Correct 18 ms 716 KB Output is correct
8 Correct 18 ms 724 KB Output is correct
9 Correct 18 ms 712 KB Output is correct
10 Correct 16 ms 588 KB Output is correct
11 Correct 16 ms 588 KB Output is correct
12 Correct 17 ms 588 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 17 ms 664 KB Output is correct
15 Correct 15 ms 680 KB Output is correct
16 Correct 15 ms 572 KB Output is correct
17 Correct 15 ms 588 KB Output is correct
18 Correct 16 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 19 ms 716 KB Output is correct
4 Correct 20 ms 732 KB Output is correct
5 Correct 19 ms 724 KB Output is correct
6 Correct 17 ms 712 KB Output is correct
7 Correct 18 ms 716 KB Output is correct
8 Correct 18 ms 724 KB Output is correct
9 Correct 18 ms 712 KB Output is correct
10 Correct 16 ms 588 KB Output is correct
11 Correct 16 ms 588 KB Output is correct
12 Correct 17 ms 588 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 17 ms 664 KB Output is correct
15 Correct 15 ms 680 KB Output is correct
16 Correct 15 ms 572 KB Output is correct
17 Correct 15 ms 588 KB Output is correct
18 Correct 16 ms 664 KB Output is correct
19 Correct 199 ms 1764 KB Output is correct
20 Correct 253 ms 1936 KB Output is correct
21 Correct 248 ms 1908 KB Output is correct
22 Correct 249 ms 1968 KB Output is correct
23 Correct 226 ms 1860 KB Output is correct
24 Correct 239 ms 1760 KB Output is correct
25 Correct 213 ms 1732 KB Output is correct
26 Correct 224 ms 1844 KB Output is correct
27 Correct 207 ms 1660 KB Output is correct
28 Correct 203 ms 1636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 412 ms 3152 KB Output is correct
2 Correct 3389 ms 7116 KB Output is correct
3 Execution timed out 9017 ms 11136 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 19 ms 716 KB Output is correct
4 Correct 20 ms 732 KB Output is correct
5 Correct 19 ms 724 KB Output is correct
6 Correct 17 ms 712 KB Output is correct
7 Correct 18 ms 716 KB Output is correct
8 Correct 18 ms 724 KB Output is correct
9 Correct 18 ms 712 KB Output is correct
10 Correct 16 ms 588 KB Output is correct
11 Correct 16 ms 588 KB Output is correct
12 Correct 17 ms 588 KB Output is correct
13 Correct 17 ms 588 KB Output is correct
14 Correct 17 ms 664 KB Output is correct
15 Correct 15 ms 680 KB Output is correct
16 Correct 15 ms 572 KB Output is correct
17 Correct 15 ms 588 KB Output is correct
18 Correct 16 ms 664 KB Output is correct
19 Correct 199 ms 1764 KB Output is correct
20 Correct 253 ms 1936 KB Output is correct
21 Correct 248 ms 1908 KB Output is correct
22 Correct 249 ms 1968 KB Output is correct
23 Correct 226 ms 1860 KB Output is correct
24 Correct 239 ms 1760 KB Output is correct
25 Correct 213 ms 1732 KB Output is correct
26 Correct 224 ms 1844 KB Output is correct
27 Correct 207 ms 1660 KB Output is correct
28 Correct 203 ms 1636 KB Output is correct
29 Correct 412 ms 3152 KB Output is correct
30 Correct 3389 ms 7116 KB Output is correct
31 Execution timed out 9017 ms 11136 KB Time limit exceeded
32 Halted 0 ms 0 KB -