結果

問題 No.1000 Point Add and Array Add
ユーザー minatominato
提出日時 2020-02-28 21:42:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 2,806 bytes
コンパイル時間 2,769 ms
コンパイル使用メモリ 187,888 KB
実行使用メモリ 16,288 KB
最終ジャッジ日時 2024-04-21 18:12:36
合計ジャッジ時間 7,026 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 217 ms
15,528 KB
testcase_17 AC 187 ms
9,728 KB
testcase_18 AC 318 ms
16,236 KB
testcase_19 AC 301 ms
16,152 KB
testcase_20 AC 275 ms
16,288 KB
testcase_21 AC 274 ms
16,176 KB
testcase_22 AC 298 ms
16,116 KB
testcase_23 AC 286 ms
16,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
struct LazySegmentTree {
    int N;
    vector<T> node,lazy;

    LazySegmentTree() = default;
    LazySegmentTree(vector<T> &v) {init(v);}

    void init(vector<T> &v) {
        int sz = v.size();
        N = 1; while (N < sz) N *= 2;
        node.assign(2*N,0); lazy.assign(2*N,0);
        for (int i = 0; i < sz; i++) node[i+N] = v[i];
        for (int i = N-1; i >= 1; i--) node[i] = node[i<<1|0] + node[i<<1|1];
    }

    void eval(int k) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];
            if (k < N) {
                lazy[k<<1|0] += lazy[k]/2;
                lazy[k<<1|1] += lazy[k]/2;
            }
            lazy[k] = 0;
        }
    }

    void update(int a, int b, T val, int k = 1, int l = 0, int r = -1) { // [a,b) (0-indexed)
        if (r < 0) r = N;

        eval(k);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r-l) * val;
            eval(k);
        } else {
            update(a, b, val, k<<1|0, l, (l+r)/2);
            update(a, b, val, k<<1|1, (l+r)/2, r);
            node[k] = node[k<<1|0] + node[k<<1|1];
        }
    }

    T get(int a, int b, int k = 1, int l = 0, int r = -1) { // [a,b) (0-indexed)
        if (r < 0) r = N;

        eval(k);
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        T vl = get(a, b, k<<1|0, l, (l+r)/2);
        T vr = get(a, b, k<<1|1, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,Q; cin >> N >> Q;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> cnt(N),B(N);
    LazySegmentTree<ll> seg(cnt);
    rep(i,Q) {
        char c;
        ll x,y; cin >> c >> x >> y;
        if (c=='A') {
            --x;
            ll k = seg.get(x,x+1);
            B[x] += k*A[x];
            seg.update(x,x+1,-k);
            A[x] += y;
        } else {
            --x;
            seg.update(x,y,1);
        }
    }
    rep(i,N) {
        ll k = seg.get(i,i+1);
        B[i] += k*A[i];
    }

    rep(i,N) cout << B[i] << " ";
    cout << ln;
}
0