結果

問題 No.1000 Point Add and Array Add
ユーザー leaf_1415
提出日時 2020-02-28 21:40:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 63,340 KB
実行使用メモリ 11,268 KB
最終ジャッジ日時 2024-10-13 17:05:10
合計ジャッジ時間 3,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n, Q;
llint a[200005];
char c[200005];
llint x[200005], y[200005];
BIT bit(200005);
llint ans[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= Q; i++){
		cin >> c[i] >> x[i] >> y[i];
	}
	
	for(int i = Q; i >= 1; i--){
		if(c[i] == 'B'){
			bit.add(x[i], 1);
			bit.add(y[i]+1, -1);
		}
		else{
			ans[x[i]] += bit.query(x[i]) * y[i];
		}
	}
	for(int i = 1; i <= n; i++){
		ans[i] += bit.query(i) * a[i];
	}
	
	for(int i = 1; i <= n; i++) cout << ans[i] << " "; cout << endl;
	
	return 0;
}
0