結果

問題 No.1000 Point Add and Array Add
ユーザー Y17Y17
提出日時 2020-02-28 21:59:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 163,460 KB
実行使用メモリ 10,408 KB
最終ジャッジ日時 2024-04-21 18:28:13
合計ジャッジ時間 5,738 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,528 KB
testcase_01 AC 4 ms
6,400 KB
testcase_02 AC 3 ms
6,528 KB
testcase_03 AC 4 ms
6,528 KB
testcase_04 AC 3 ms
6,656 KB
testcase_05 AC 3 ms
6,528 KB
testcase_06 AC 4 ms
6,528 KB
testcase_07 AC 3 ms
6,656 KB
testcase_08 AC 3 ms
6,656 KB
testcase_09 AC 3 ms
6,272 KB
testcase_10 AC 3 ms
6,656 KB
testcase_11 AC 3 ms
6,528 KB
testcase_12 AC 5 ms
6,528 KB
testcase_13 AC 4 ms
6,656 KB
testcase_14 AC 6 ms
6,528 KB
testcase_15 AC 6 ms
6,656 KB
testcase_16 AC 222 ms
10,316 KB
testcase_17 AC 179 ms
8,448 KB
testcase_18 AC 306 ms
10,248 KB
testcase_19 AC 311 ms
10,320 KB
testcase_20 AC 261 ms
10,248 KB
testcase_21 AC 295 ms
10,408 KB
testcase_22 AC 283 ms
10,316 KB
testcase_23 AC 329 ms
10,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

template< typename OperatorMonoid >
struct DuelSegmentTree {
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

  int sz, height;
  vector< OperatorMonoid > lazy;
  const H h;
  const OperatorMonoid OM0;


  DuelSegmentTree(int n, const H h, const OperatorMonoid OM0)
      : h(h), OM0(OM0) {
    sz = 1;
    height = 0;
    while(sz < n) sz <<= 1, height++;
    lazy.assign(2 * sz, OM0);
  }

  inline void propagate(int k) {
    if(lazy[k] != OM0) {
      lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      lazy[k] = OM0;
    }
  }

  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }

  void update(int a, int b, const OperatorMonoid &x) {
    thrust(a += sz);
    thrust(b += sz - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) lazy[l] = h(lazy[l], x), ++l;
      if(r & 1) --r, lazy[r] = h(lazy[r], x);
    }
  }

  OperatorMonoid operator[](int k) {
    thrust(k += sz);
    return lazy[k];
  }
};

signed main(){
	int n, q;
	cin >> n >> q;

	int a[200010];
	for(int i = 0;i < n;i++) cin >> a[i];

	DuelSegmentTree<int> seg(n, [](int a, int b){
		return a + b; 
	}, 0);

	int b[200010] = {};
	
	for(int i = 0;i < q;i++){
		char c;
		int x, y;
		cin >> c >> x >> y;
		x--;
		if(c == 'A'){
			b[x] += a[x] * seg[x];
			seg.update(x, x+1, -seg[x]);
			a[x] += y;
		}else{
			seg.update(x, y, 1);
		}
	}

	for(int i = 0;i < n;i++){
		b[i] += a[i] * seg[i];
		cout << b[i];
		if(i < n-1){
			cout << " ";
		}else{
			cout << endl;
		}
	}

	return 0;
}
0