結果

問題 No.1000 Point Add and Array Add
ユーザー furafura
提出日時 2020-07-25 18:23:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 2,757 ms
コンパイル使用メモリ 202,800 KB
実行使用メモリ 9,024 KB
最終ジャッジ日時 2023-09-09 19:13:00
合計ジャッジ時間 6,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 85 ms
7,556 KB
testcase_17 AC 68 ms
6,148 KB
testcase_18 AC 113 ms
9,024 KB
testcase_19 AC 113 ms
8,552 KB
testcase_20 AC 100 ms
8,592 KB
testcase_21 AC 117 ms
8,964 KB
testcase_22 AC 108 ms
8,952 KB
testcase_23 AC 116 ms
8,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class G>
class Fenwick_tree_dual{
	vector<G> a;
public:
	Fenwick_tree_dual(int n):a(n){}
	void add(int l,int r,const G& val){
		if(l==0){
			for(;r>0;r-=r&-r) a[r-1]+=val;
			return;
		}
		add(0,r,val);
		add(0,l,-val);
	}
	G sum(int i)const{
		G res{};
		for(i++;i<=a.size();i+=i&-i) res+=a[i-1];
		return res;
	}
};

int main(){
	int n,q; scanf("%d%d",&n,&q);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);
	vector<char> type(q);
	vector<int> x(q),y(q);
	rep(i,q) scanf(" %c%d%d",&type[i],&x[i],&y[i]), x[i]--;

	Fenwick_tree_dual<int> F(n);
	rep(i,q) if(type[i]=='B') F.add(x[i],y[i],1);

	vector<lint> res(n);
	rep(i,n) res[i]+=a[i]*F.sum(i);
	rep(i,q){
		if(type[i]=='A'){
			res[x[i]]+=lint(y[i])*F.sum(x[i]);
		}
		else{
			F.add(x[i],y[i],-1);
		}
	}
	rep(i,n) printf("%lld%c",res[i],i<n-1?' ':'\n');

	return 0;
}
0