結果

問題 No.1000 Point Add and Array Add
ユーザー けーむけーむ
提出日時 2020-05-13 10:04:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 3,767 bytes
コンパイル時間 2,709 ms
コンパイル使用メモリ 183,116 KB
実行使用メモリ 20,884 KB
最終ジャッジ日時 2023-10-12 16:51:57
合計ジャッジ時間 9,018 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 4 ms
4,352 KB
testcase_15 AC 4 ms
4,352 KB
testcase_16 AC 279 ms
18,472 KB
testcase_17 AC 264 ms
13,144 KB
testcase_18 AC 437 ms
20,780 KB
testcase_19 AC 442 ms
20,672 KB
testcase_20 AC 189 ms
20,740 KB
testcase_21 AC 485 ms
20,884 KB
testcase_22 AC 333 ms
20,804 KB
testcase_23 AC 494 ms
20,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<class T, class E>
struct LazySegmentTree {
private:
    int n;
    vector<T> node;
    vector<E> lazy;
    vector<bool> updated;
    T def;
    function<T(T,T)> out;
    function<T(T,E,int)> app;
    function<E(E,E)> lop;
    
    void propagate(int k, E x) {
        if (updated[k]) {
            lazy[k] = lop(lazy[k], x);
        }
        else {
            lazy[k] = x;
            updated[k] = true;
        }
    }
    
    void evaluate(int k, int l, int r) {
        if (updated[k]) {
            node[k] = app(node[k], lazy[k], r - l);
            if ((r - l) > 1) {
                propagate(k * 2 + 1, lazy[k]);
                propagate(k * 2 + 2, lazy[k]);
            }
            updated[k] = false;
        }
    }
    
public:
    LazySegmentTree() {}
    LazySegmentTree(const vector<T> &v, T _def, function<E(E,E)> _lop, function<T(T,E,int)> _app, function<T(T,T)> _out) {
        def = _def; out = _out; app = _app; lop = _lop;
        int vl = (int)v.size();
        n = 1; while(n < vl) n *= 2;
        node.resize(2 * n - 1, def);
        lazy.resize(2 * n - 1);
        updated.resize(2 * n - 1, false);
        for(int i = 0; i < vl; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    void update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        evaluate(k, l, r);
        if((b <= l) || (r <= a)) return;
        if((a <= l) && (r <= b)) {
            propagate(k, x);
            evaluate(k, l, r);
        }
        else {
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = out(node[2 * k + 1], node[2 * k + 2]);
        }
    }
    
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        evaluate(k, l, r);
        if ((b <= l) || (r <= a)) return def;
        if ((a <= l) && (r <= b)) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return out(vl, vr);
    }
};

struct S {
    char c;
    ll x, y;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<S> vs(q);
    rep(i, q) cin >> vs[i].c >> vs[i].x >> vs[i].y;
    vector<ll> val(n, 0), cnt(n + 1, 0);
    rep(i, q) {
        if (vs[i].c == 'A') {
            vs[i].x--;
        }
        else {
            vs[i].x--; vs[i].y--;
            cnt[vs[i].x]++;
            cnt[vs[i].y + 1]--;
        }
    }
    rep(i, n) cnt[i + 1] += cnt[i];
    auto lop = [](ll a, ll b){ return a + b; };
    auto app = [](ll a, ll b, int c){ return a + b * c; };
    auto out = [](ll a, ll b){ return a + b; };
    LazySegmentTree<ll, ll> lst(cnt, 0, lop, app, out);
    rep(i, q) {
        if (vs[i].c == 'A') {
            val[vs[i].x] += lst.query(vs[i].x, vs[i].x + 1) * vs[i].y;
        }
        else {
            lst.update(vs[i].x, vs[i].y + 1, -1);
        }
    }
    rep(i, n) {
        ll b = cnt[i] * a[i] + val[i];
        printf("%lld%s", b, (i == (n - 1)) ? "\n" : " ");
    }
    return 0;
}
0