結果

問題 No.1000 Point Add and Array Add
ユーザー lotuslotus
提出日時 2020-02-28 22:04:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,780 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 163,624 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-04-21 18:32:20
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 156 ms
14,464 KB
testcase_17 AC 124 ms
10,624 KB
testcase_18 AC 213 ms
16,128 KB
testcase_19 AC 216 ms
16,128 KB
testcase_20 AC 170 ms
9,856 KB
testcase_21 AC 195 ms
11,392 KB
testcase_22 AC 180 ms
11,392 KB
testcase_23 AC 196 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, Q, a[202020], x[202020], y[202020];
char c[202020];
i64 d[202020], b[202020];

///////////////////
// L,R,Xが与えられるので,A_L~A_RにXを加える
// L,Rが与えられるので、A_L~A_Rの和を求める
i64 seg1[(1<<19)-1], seg2[(1<<19)-1];
void add(int a, int b, i64 x, int k, int l, int r){
	if(a <= l && r <= b){
		seg1[k] += x;
	}
	else if(l < b && a < r){
		seg2[k] += (min(b,r) - max(a,l)) * x;
		add(a,b,x,k*2+1,l,(l+r)/2);
		add(a,b,x,k*2+2,(l+r)/2,r);
	}
}
i64 sum(int a, int b, int k, int l, int r){
	if(b <= l || r <= a){
		return 0;
	}
	else if(a <= l && r <= b){
		return seg1[k] * (r-l) + seg2[k];
	}
	else{
		i64 res = (min(b,r) - max(a,l)) * seg1[k];
		res += sum(a,b,k*2+1,l,(l+r)/2);
		res += sum(a,b,k*2+2,(l+r)/2,r);
		return res;
	}
}
///////

void solve(){
	cin >> n >> Q;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < Q; i++){
		cin >> c[i] >> x[i] >> y[i];
		x[i]--;
	}
	for(int i = Q-1; i >= 0; i--){
		if(c[i] == 'B'){
			//足していきたい
			add(x[i], y[i], 1, 0,0,n);
		}
		else{
			//b[x[i]] += y[i]*d[x[i]];
			b[x[i]] += y[i]*(sum(x[i],x[i]+1,0,0,n));
		}
	}
	for(int i = 0; i < n; i++){
		//b[i] += a[i]*d[i];
		b[i] += a[i]*(sum(i,i+1,0,0,n));
		cout << b[i] << " ";
	}
	cout << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}
0