結果

問題 No.1000 Point Add and Array Add
ユーザー iqueue02iqueue02
提出日時 2020-02-28 22:06:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 2,044 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 173,324 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-04-21 19:00:00
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
5,376 KB
testcase_16 AC 287 ms
10,880 KB
testcase_17 AC 231 ms
8,192 KB
testcase_18 AC 392 ms
12,032 KB
testcase_19 AC 392 ms
12,160 KB
testcase_20 AC 311 ms
12,032 KB
testcase_21 AC 410 ms
12,032 KB
testcase_22 AC 349 ms
12,032 KB
testcase_23 AC 409 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

template <typename T> 
struct LazySegmentTree {
  
  int n;
  vector<T> node, lazy;

  LazySegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
    lazy.assign(2*n, 0); /*区間加算の時は0*/
  }

  void eval (int k) {
    if (lazy[k] == 0) return ;
    node[k] += lazy[k]; /*区間加算に注意*/
    if (k < n) {
      lazy[2*k+1] += lazy[k];
      lazy[2*k+2] += lazy[k];
    }
    lazy[k] = 0;
  }

  void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
    eval(k);
    if (r < 0) r = n;
    if (b <= l || r <= a) return ;
    if (a <= l && r <= b) {
      lazy[k] = x;
      eval(k);
    } else {
      update(a, b, x, 2*k+1, l, (r+l)/2);
      update(a, b, x, 2*k+2, (r+l)/2, r);
      node[k] = node[2*k+1] + node[2*k+2];
    }
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    eval(k);
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }

};

int main(){
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  LazySegmentTree<int> seg(n);
  vector<pair<char, P>> query(q);

  rep(i,q) {
    char c;
    int x, y;
    cin >> c >> x >> y;
    x--;
    query[i].first = c;
    query[i].second.first = x;
    query[i].second.second = y;
  }

  reverse(query.begin(), query.end());
  vector<ll> res(n,0);

  for (int i = 0; i < q; i++) {
    char c = query[i].first;
    int x = query[i].second.first, y = query[i].second.second;
    if (c == 'A') { 
      res[x] += (ll)seg.query(x, x + 1) * y;
    } else {
      seg.update(x, y, 1);
    }
  }
  for (int i = 0; i < n; i++) {
    res[i] += (ll)a[i] * seg.query(i, i + 1);
  }
  for (int i = 0; i < n; i++) cout << res[i] << " ";
  cout << endl;
  return 0;
}
0