QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771468#5441. Quartz Collectionucup-team3702WA 1ms5988kbC++202.1kb2024-11-22 13:18:242024-11-22 13:18:24

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 13:18:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5988kb
  • [2024-11-22 13:18:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define pv(a) cout << #a" = " << a << endl
#define pa(a, l, r) cout << #a" : "; rep(_, l, r) cout << a[_] << " \n"[_ == r]

using i64 = long long;

const int N = 2e5 + 10;
const int M = 20;
const int W = 10;

int n, m, a[N], b[N];
i64 base;

#define ls lson[u]
#define rs rson[u]
#define mid ((l + r) >> 1)

int rt, tot, lson[N * M], rson[N * M], cnt[N * M];
i64 dat[N * M][4];

void maintain(int u, int l, int r) {
  cnt[u] = cnt[ls] + cnt[rs];
  rep(o, 0, 3) {
    if (u == 1) {
      dat[u][o] = dat[rs][o] + dat[ls][(cnt[rs] & 1) ? 2 : 0];
    } else if (r <= 0) {
      dat[u][o] = dat[ls][o] + dat[rs][(o + cnt[ls]) & 3];
    } else {
      dat[u][o] = dat[rs][o] + dat[ls][(o + cnt[rs]) & 3];
    }
  }
}

int modify(int p, int k, int u, int l, int r) {
  if (!u) u = ++tot;
  if (l == r) {
    cnt[u] += k;
    i64 t = (i64) (cnt[u] / 4) * 2 * p;
    // pv(t);
    dat[u][0] = t + p * (cnt[u] % 4 >= 1);
    dat[u][1] = t + p * (cnt[u] % 4 >= 3);
    dat[u][2] = t + p * ((cnt[u] % 4 >= 2) + (cnt[u] % 4 >= 3));
    dat[u][3] = t + p * ((cnt[u] % 4 >= 1) + (cnt[u] % 4 >= 2));
    return u;
  }
  if (p <= mid) ls = modify(p, k, ls, l, mid);
  else rs = modify(p, k, rs, mid + 1, r);
  maintain(u, l, r);
  return u;
}

#undef ls
#undef rs
#undef mid

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    cin >> a[i] >> b[i];
    base += b[i];
    rt = modify(b[i] - a[i], 1, rt, -W, W);
    // pv(cnt[rt]);
    // pa(dat[rt], 0, 3);
  }
  // pv(base);
  // pv(lson[1]);
  // pv(rson[1]);
  // pa(dat[lson[1]], 0, 3);
  // pa(dat[rson[1]], 0, 3);
  printf("%lld\n", base - dat[rt][0]);
  while (m--) {
    int p, x, y;
    cin >> p >> x >> y;
    base -= b[p];
    rt = modify(b[p] - a[p], -1, rt, -W, W);
    a[p] = x, b[p] = y;
    base += b[p];
    rt = modify(b[p] - a[p], 1, rt, -W, W);
    // pa(dat[rt], 0, 3);
    // pv(base);
    // pa(a, 1, n);
    // pa(b, 1, n);
    printf("%lld\n", base - dat[rt][0]);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5988kb

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
16
17
13
13

result:

wrong answer 3rd numbers differ - expected: '15', found: '16'