結果

問題 No.1000 Point Add and Array Add
ユーザー pekempeypekempey
提出日時 2020-02-28 22:40:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 167,832 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-04-21 19:49:49
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 164 ms
8,320 KB
testcase_17 AC 139 ms
7,040 KB
testcase_18 AC 225 ms
9,856 KB
testcase_19 AC 226 ms
9,728 KB
testcase_20 AC 219 ms
9,856 KB
testcase_21 AC 229 ms
9,728 KB
testcase_22 AC 222 ms
9,728 KB
testcase_23 AC 227 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

template<class T>
struct BIT {
  vector<T> dat;

  BIT(int n) : dat(n + 1) {}

  void update(int k, T v) {
    for (int i = k + 1; i < dat.size(); i += i & -i) {
      dat[i] += v;
    }
  }

  T query(int k) {
    T res = 0;
    for (int i = k + 1; i > 0; i -= i & -i) {
      res += dat[i];
    }
    return res;
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  BIT<ll> bit(N + 1);
  vector<char> C(Q);
  vector<int> X(Q), Y(Q);
  rep(i, Q) {
    cin >> C[i] >> X[i] >> Y[i];
    X[i]--;
  }
  vector<ll> ans(N);
  repr(i, Q) {
    if (C[i] == 'A') {
      ans[X[i]] += bit.query(X[i]) * Y[i];
    } else {
      bit.update(X[i], 1);
      bit.update(Y[i], -1);
    }
  }
  rep(i, N) {
    ans[i] += bit.query(i) * A[i];
  }
  rep(i, N) cout << ans[i] << " \n"[i == N - 1];
}
0