結果

問題 No.1000 Point Add and Array Add
ユーザー hirokazu1020hirokazu1020
提出日時 2020-02-28 21:58:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,859 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 97,748 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-21 18:27:53
合計ジャッジ時間 3,421 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 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 2 ms
5,376 KB
testcase_16 AC 77 ms
8,960 KB
testcase_17 AC 60 ms
7,168 KB
testcase_18 AC 102 ms
10,368 KB
testcase_19 AC 103 ms
10,368 KB
testcase_20 AC 91 ms
10,368 KB
testcase_21 AC 97 ms
10,496 KB
testcase_22 AC 94 ms
10,368 KB
testcase_23 AC 100 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


class BIT {//binary indexed tree, Fenwick treeとも
	int lg;
	std::vector<long long> bit;
public:
	BIT(int size) :bit(size + 1, 0) {
		lg = size;
		while (lg & lg - 1)lg &= lg - 1;
	}
	void add(int i, int x) {//i番目にx加える
		i++;//BIT添え字は1~nだから
		while (i < (int)bit.size()) {
			bit[i] += x;
			i += i & -i;
		}
	}
	int sum(int a)const {//[0,a]の和
		a++;
		int res = 0;
		while (0 < a) {
			res += bit[a];
			a -= a & -a;
		}
		return res;
	}
	long long sum(int a, int b)const {//[a,b]の合計
		return sum(b) - sum(a - 1);
	}
};


int n, q;
char c[200000];
int x[200000];
int y[200000];
int a[200000];
long long b[200000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> q;
	rep(i, n)cin >> a[i];
	rep(i,q) {
		cin >> c[i] >> x[i] >> y[i];
	}

	long long cnt = 0;
	BIT le(n), ri(n);
	for (int i = q - 1; i >= 0; i--) {
		if (c[i] == 'A') {
			x[i]--;
			b[x[i]] += y[i] * (cnt - le.sum(x[i]) - ri.sum(n - 1 - x[i]));
		}
		else {
			cnt++;
			x[i]--;
			y[i]--;
			if (y[i] + 1 < n)le.add(y[i] + 1, 1);
			if (0 < x[i])ri.add(n - 1 - (x[i] - 1), 1);
		}
	}
	rep(i, n) {
		b[i] += a[i] * (cnt - le.sum(i) - ri.sum(n - 1 - i));
	}
	rep(i, n) {
		if (i)cout << ' ';
		cout << b[i];
	}
	cout << endl;


	return 0;
}
0