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>
#include "bubblesort2.h"
using namespace std;
const int64_t INF = 1e16L;
struct ST {
  int n;
  vector<int64_t> 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, int64_t 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, int64_t 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, int64_t v) {
    if (dr < st) {
      return;
    }
    update(1, 0, n - 1, st, dr, v);
  }
  int64_t 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 int64_t &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 | 
|---|
| 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... |