結果

問題 No.1000 Point Add and Array Add
ユーザー leaf_1415leaf_1415
提出日時 2020-02-28 21:40:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 63,144 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-21 18:09:13
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,960 KB
testcase_01 AC 4 ms
8,828 KB
testcase_02 AC 4 ms
8,824 KB
testcase_03 AC 3 ms
8,832 KB
testcase_04 AC 4 ms
8,824 KB
testcase_05 AC 4 ms
8,836 KB
testcase_06 AC 4 ms
8,960 KB
testcase_07 AC 4 ms
8,832 KB
testcase_08 AC 4 ms
8,960 KB
testcase_09 AC 4 ms
8,828 KB
testcase_10 AC 4 ms
8,832 KB
testcase_11 AC 4 ms
8,832 KB
testcase_12 AC 5 ms
8,848 KB
testcase_13 AC 4 ms
8,960 KB
testcase_14 AC 5 ms
10,880 KB
testcase_15 AC 5 ms
8,828 KB
testcase_16 AC 72 ms
10,628 KB
testcase_17 AC 58 ms
10,148 KB
testcase_18 AC 96 ms
11,136 KB
testcase_19 AC 96 ms
11,136 KB
testcase_20 AC 85 ms
11,100 KB
testcase_21 AC 97 ms
11,080 KB
testcase_22 AC 91 ms
11,120 KB
testcase_23 AC 95 ms
11,132 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