結果

問題 No.1000 Point Add and Array Add
ユーザー ninoinuininoinui
提出日時 2020-07-19 01:47:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,909 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 208,216 KB
実行使用メモリ 9,488 KB
最終ジャッジ日時 2023-08-21 12:41:21
合計ジャッジ時間 7,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 70 ms
7,728 KB
testcase_17 AC 56 ms
6,728 KB
testcase_18 AC 93 ms
9,312 KB
testcase_19 AC 93 ms
9,488 KB
testcase_20 AC 83 ms
9,328 KB
testcase_21 AC 97 ms
9,340 KB
testcase_22 AC 90 ms
9,264 KB
testcase_23 AC 96 ms
9,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T> class FenwickTree {
private:
  int n, mx;
  vector<T> bit;
public:
  FenwickTree(int sz) : n(sz + 1), mx(1), bit(n, 0) {
      while (mx * 2 <= n) mx *= 2;
  }
  FenwickTree(const vector<T> &v) : n((int) v.size() + 1), mx(1), bit(n, 0) {
    for (int i = 0; i < n - 1; i++) add(i, v.at(i));
    while (mx * 2 <= n) mx *= 2;
  }
  void add(int i, T x) {
    i++;
    while (i < n) bit.at(i) += x, i += i & -i;
  }
  void add(int l, int r, T x) {
    add(l, x);
    add(r + 1 , -x);
  }
  T sum(int i) {
    i++;
    T ret = 0;
    while (i > 0) ret += bit.at(i), i -= i & -i;
    return ret;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }
  int lower_bound(T w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int k = mx; k > 0; k /= 2) {
      if (x + k <= n - 1 && bit.at(x + k) < w) {
        w -= bit.at(x + k);
        x += k;
      }
    }
    return x;
  }
  int upper_bound(T w) {
    if (w < 0) return 0;
    int x = 0;
    for (int k = mx; k > 0; k /= 2) {
      if (x + k <= n - 1 && bit.at(x + k) <= w) {
        w -= bit.at(x + k);
        x += k;
      }
    }
    return x;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<tuple<char, int, int>> V(Q);
  for (int i = 0; i < Q; i++) {
    char c;
    int x, y;
    cin >> c >> x >> y;
    V.at(i) = {c, x, y};
  }
  reverse(V.begin(), V.end());
  vector<long> ans(N);
  FenwickTree<long> FT(N);
  for (auto [c, x, y] : V) {
    if (c == 'A') {
      x--;
      ans.at(x) += (long) y * FT.sum(x);
    } else {
      x--, y--;
      FT.add(x, y, 1);
    }
  }
  for (int i = 0; i < N; i++) {
    ans.at(i) += (long) A.at(i) * FT.sum(i);
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << ((i == N - 1) ? "\n" : " ");
  }
}
0