LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/8/23 daily

CF 627B

struct fenwick {
  ll PartialSum[MAXN];
  fenwick() {
    for (int i = 0; i < MAXN; i++) PartialSum[i] = 0;
  }
  inline void add(ll index, ll increase) {
    while (index < MAXN) {
      PartialSum[index] += increase;
      index += index & -index;
    }
  }
  inline ll get(int index) {
    ll sum = 0;
    while (index) {
      sum += PartialSum[index];
      index -= index & -index;
    }
    return sum;
  }
};
void solve() {
  ll n, k, a, b, q;
  cin >> n >> k >> a >> b >> q;
  vector<ll> A(n + 1);
  int type;
  fenwick t1, t2;
  int x, y;
  while (q--) {
    cin >> type;
    switch (type) {
      case 1: {
        cin >> x >> y;
        auto cur = A[x];
        A[x] += y;
        t1.add(x, min(b, A[x]) - min(b, cur));
        t2.add(x, min(a, A[x]) - min(a, cur));
        break;
      }
      case 2: {
        cin >> x;
        cout << t1.get(x - 1) + t2.get(n) - t2.get(x + k - 1) << '\n';
        break;
      }
      default: {
        break;
      }
    }
  }
  return;
}

CF 986B