結果

問題 No.1000 Point Add and Array Add
ユーザー kenken714kenken714
提出日時 2020-02-28 22:12:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 586 ms / 2,000 ms
コード長 2,557 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 96,572 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-04-21 19:03:24
合計ジャッジ時間 6,598 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 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 3 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 5 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 350 ms
16,992 KB
testcase_17 AC 299 ms
11,264 KB
testcase_18 AC 518 ms
17,920 KB
testcase_19 AC 513 ms
17,792 KB
testcase_20 AC 320 ms
17,920 KB
testcase_21 AC 586 ms
17,792 KB
testcase_22 AC 390 ms
17,920 KB
testcase_23 AC 575 ms
17,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(ll sz) {
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);
    }

    void eval(int k, int l, int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];
            if (r - l > 1) {
                lazy[2 * k + 1] += lazy[k] / 2;
                lazy[2 * k + 2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
};


ll n, q, ans[210000];
ll a[210000], b[210000];
char c[210000];
int main() {
	cin >> n >> q;
    LazySegmentTree seg(n);
	vector<ll> s(n), in;
	REP(i, n)cin >> s[i];
	
	REP(i, q) {
		cin >> c[i] >> a[i] >> b[i];
		if (c[i] == 'B')  seg.add(a[i] - 1, b[i], 1);
	}
    REP(i, n)ans[i] += seg.getsum(i, i + 1) * s[i];
    REP(i, q) {
        if (c[i] == 'A') {
            ans[a[i] - 1] += seg.getsum(a[i] - 1, a[i]) * b[i];
        }
        else seg.add(a[i] - 1, b[i], -1);

    }
    REP(i, n) {
        if (i != 0)cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

0