結果

問題 No.1000 Point Add and Array Add
ユーザー leaf_1415leaf_1415
提出日時 2020-02-28 21:40:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 3,022 ms
コンパイル使用メモリ 64,272 KB
実行使用メモリ 11,068 KB
最終ジャッジ日時 2023-08-03 19:52:01
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,464 KB
testcase_01 AC 4 ms
8,660 KB
testcase_02 AC 4 ms
8,500 KB
testcase_03 AC 4 ms
8,640 KB
testcase_04 AC 4 ms
8,460 KB
testcase_05 AC 4 ms
8,660 KB
testcase_06 AC 4 ms
8,668 KB
testcase_07 AC 4 ms
8,592 KB
testcase_08 AC 4 ms
8,464 KB
testcase_09 AC 4 ms
8,504 KB
testcase_10 AC 4 ms
8,460 KB
testcase_11 AC 4 ms
8,468 KB
testcase_12 AC 4 ms
8,636 KB
testcase_13 AC 4 ms
8,584 KB
testcase_14 AC 5 ms
8,616 KB
testcase_15 AC 5 ms
8,684 KB
testcase_16 AC 74 ms
10,576 KB
testcase_17 AC 61 ms
9,952 KB
testcase_18 AC 99 ms
11,068 KB
testcase_19 AC 98 ms
11,064 KB
testcase_20 AC 86 ms
11,036 KB
testcase_21 AC 99 ms
11,044 KB
testcase_22 AC 94 ms
10,992 KB
testcase_23 AC 99 ms
11,036 KB
権限があれば一括ダウンロードができます

ソースコード

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