Submission #526367

# Submission time Handle Problem Language Result Execution time Memory
526367 2022-02-14T13:45:43 Z Alex_tz307 Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
47 ms 3112 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#define INF 0x3f3f3f3f

using namespace std;

struct ST {
  int n;
  vector<int> t, lazy;

  ST(int N) : n(N) {
    int dim = 1;
    while (dim < n) {
      dim *= 2;
    }
    dim *= 2;
    t.resize(dim, -INF);
    lazy.resize(dim);
  }

  void updateNode(int x, int v) {
    t[x] += v;
    lazy[x] += v;
  }

  void push(int x) {
    if (lazy[x] == 0) {
      return;
    }
    for (int i = 0; i < 2; ++i) {
      updateNode(x * 2 + i, lazy[x]);
    }
    lazy[x] = 0;
  }

  void update(int x, int lx, int rx, int st, int dr, int v) {
    if (st <= lx && rx <= dr) {
      updateNode(x, v);
      return;
    }
    push(x);
    int mid = (lx + rx) / 2;
    if (st <= mid) {
      update(x * 2, lx, mid, st, dr, v);
    }
    if (mid < dr) {
      update(x * 2 + 1, mid + 1, rx, st, dr, v);
    }
    t[x] = max(t[x * 2], t[x * 2 + 1]);
  }

  void update(int st, int dr, int v) {
    if (dr < st) {
      return;
    }
    update(1, 0, n - 1, st, dr, v);
  }

  int getMax() {
    return t[1];
  }
};

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
  int n = a.size(), q = x.size();
  vector<pair<int, int>> pairs;
  pairs.reserve(n + q);
  for (int i = 0; i < n; ++i) {
    pairs.emplace_back(a[i], i);
  }
  for (int i = 0; i < q; ++i) {
    pairs.emplace_back(v[i], x[i]);
  }
  sort(pairs.begin(), pairs.end());
  map<pair<int, int>, int> order;
  order[pairs[0]] = 1;
  int N = 0;
  for (int i = 1; i < (int)pairs.size(); ++i) {
    if (pairs[i] != pairs[i - 1]) {
      N += 1;
    }
    order[pairs[i]] = N;
  }
  N += 1;
  ST t(N);
  auto update = [&](const int &index, const int &pos, const int &sgn) -> void {
    t.update(index, index, sgn * INF);
    t.update(index, index, sgn * pos);
    t.update(index + 1, N - 1, -sgn);
  };
  for (int i = 0; i < n; ++i) {
    update(order[{a[i], i}], i, 1);
  }
  vector<int> sol(q);
  for (int i = 0; i < q; ++i) {
    update(order[{a[x[i]], x[i]}], x[i], -1);
    a[x[i]] = v[i];
    update(order[{a[x[i]], x[i]}], x[i], 1);
    sol[i] = t.getMax();
  }
  return sol;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Incorrect 2 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Incorrect 2 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 3112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Incorrect 2 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -