結果

問題 No.1000 Point Add and Array Add
ユーザー niuezniuez
提出日時 2020-02-28 21:33:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,053 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 170,968 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-21 17:58:52
合計ジャッジ時間 6,120 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 204 ms
12,116 KB
testcase_17 AC 172 ms
9,404 KB
testcase_18 AC 276 ms
13,952 KB
testcase_19 AC 277 ms
13,824 KB
testcase_20 AC 270 ms
13,824 KB
testcase_21 AC 272 ms
13,952 KB
testcase_22 AC 277 ms
13,824 KB
testcase_23 AC 270 ms
13,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

#include <vector>
using i64 = long long;

template<class T, class Ope, const T& Ide>
struct segment_tree {
  Ope ope;
 
  i64 n;
  std::vector<T> node;
 
  segment_tree(const std::vector<T>& init) {
    n = 1;
    while(n < init.size()) n *= 2;
    node.resize(2 * n, Ide);
    for(int i = 0;i < init.size();i++) node[i + n] = init[i];
    for(int i = n - 1; i >= 1;i--) node[i] = ope(node[i * 2], node[i * 2 + 1]);
  }
 
  void modify(i64 i, T x) {
    i += n;
    node[i] = ope(node[i], x);
    while(i > 1) {
      i = i / 2;
      node[i] = ope(node[i * 2], node[i * 2 + 1]);
    }
  }

  /* [l, r) */
  T sum(i64 l, i64 r) const {
    T lx = Ide;
    T rx = Ide;
    l += n;
    r += n;
    while(l < r) {
      if(l & 1) { lx = ope(lx, node[l++]); }
      if(r & 1) { rx = ope(node[--r], rx); }
      l >>= 1;
      r >>= 1;
    }
    return ope(lx, rx);
  }
};

const i64 IDE = 0;
using segtree = segment_tree<i64, std::plus<i64>, IDE>;

int main() {
  i64 N, Q;
  cin >> N >> Q;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  vector<char> C(Q);
  vector<i64> X(Q), Y(Q);
  rep(i,0,Q) {
    cin >> C[i] >> X[i] >> Y[i];
  }
  segtree seg(vector<i64>(N + 1));
  vector<i64> B(N);
  for(i64 q = Q; q --> 0;) {
    char c = C[q];
    i64 x = X[q] - 1;
    i64 y = Y[q];
    if(c == 'B') {
      seg.modify(x, 1);
      seg.modify(y, -1);
    }
    else {
      B[x] += seg.sum(0, x + 1) * y;
    }
  }
  for(i64 i = 0;i < N;i++) {
    B[i] += seg.sum(0, i + 1) * A[i];
  }
  for(i64 i = 0;i < N;i++) {
    cout << B[i] << " \n"[i + 1 == N];
  }
}
0