結果

問題 No.1000 Point Add and Array Add
ユーザー yakkiyakki
提出日時 2020-02-29 03:00:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 1,488 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 126,592 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-21 21:18:43
合計ジャッジ時間 5,537 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 186 ms
7,808 KB
testcase_17 AC 152 ms
6,784 KB
testcase_18 AC 251 ms
9,088 KB
testcase_19 AC 251 ms
8,960 KB
testcase_20 AC 238 ms
8,832 KB
testcase_21 AC 253 ms
8,832 KB
testcase_22 AC 250 ms
8,960 KB
testcase_23 AC 250 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

template<typename T>
struct BIT{
	vector<T> bit;
	BIT(int sz){
		bit.resize(sz);
	}
	void add(int k, T x){ //k番目にxを加える
		for(int i = k; i < bit.size(); i |= i+1) bit[i] += x;	
	}
	T sum(int k){ //[0,k)の区間の総和を求める
		T res = 0;
		for(int i = k-1; i >= 0; i = (i & (i+1))-1){
			res += bit[i];
		}
		return res;
	}
};



int main(){
	int N,Q; cin >> N >> Q;
	vector<ll> A(N);
	rep(i,N) cin >> A[i];
	vector<char> c(Q);
	vector<int> x(Q),y(Q);
	rep(i,Q) cin >> c[i] >> x[i] >> y[i];
	BIT<int> bit(N+1);
	vector<ll> ans(N);
	for(int i = Q-1; i >= 0; i--){
		x[i]--;
		if(c[i] == 'A'){
			ans[x[i]] += (ll)y[i]*(bit.sum(x[i]+1));
		}
		else{
			bit.add(x[i],1);
			bit.add(y[i],-1);
		}
	}
	rep(i,N){
		cout << ans[i]+(ll)A[i]*bit.sum(i+1) << " ";
	}
	cout << endl;
}

0