結果

問題 No.1000 Point Add and Array Add
ユーザー startcppstartcpp
提出日時 2020-02-28 21:44:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 68,296 KB
実行使用メモリ 14,032 KB
最終ジャッジ日時 2024-10-13 17:11:13
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

//区間加算、1点クエリ
const int DEPTH = 18;
struct SegTree {
	int val[1 << (DEPTH + 1)];
	SegTree() {
		int i;
		rep(i, (1 << (DEPTH + 1))) val[i] = 0;
	}
	void add(int l, int r, int x, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) { val[id] += x; return; }
		add(l, r, x, a, (a + b) / 2, id * 2 + 1);
		add(l, r, x, (a + b) / 2, b, id * 2 + 2);
	}
	int get(int pos) {
		pos += (1 << DEPTH) - 1;
		int ret = val[pos];
		while (pos > 0) {
			pos = (pos - 1) / 2;
			ret += val[pos];
		}
		return ret;
	}
};

int n, q;
int a[200000];
char c[200000]; int x[200000], y[200000];
SegTree seg;
int B[200000];

signed main() {
	int i;
	
	cin >> n >> q;
	rep(i, n) cin >> a[i];
	rep(i, q) {
		cin >> c[i] >> x[i] >> y[i];
		x[i]--;
	}
	
	rep(i, q) {
		if (c[i] == 'B') {
			seg.add(x[i], y[i], 1);	//[x, y)
		}
	}
	
	rep(i, n) {
		B[i] = seg.get(i) * a[i];
	}
	
	rep(i, q) {
		if (c[i] == 'A') {
			B[x[i]] += seg.get(x[i]) * y[i];
		}
		else {
			seg.add(x[i], y[i], -1);
		}
	}
	
	rep(i, n) {
		cout << B[i];
		if (i + 1 < n) cout << " ";
	}
	cout << endl;
	return 0;
}
0