結果

問題 No.1000 Point Add and Array Add
ユーザー kimiyukikimiyuki
提出日時 2020-02-28 21:54:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 3,094 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 201,760 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-21 18:25:08
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 1 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 5 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 206 ms
7,936 KB
testcase_17 AC 179 ms
6,016 KB
testcase_18 AC 286 ms
8,448 KB
testcase_19 AC 288 ms
8,448 KB
testcase_20 AC 253 ms
8,448 KB
testcase_21 AC 322 ms
8,448 KB
testcase_22 AC 249 ms
8,448 KB
testcase_23 AC 314 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#line 2 "/home/ubuntu/Library/utils/macros.hpp"
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#line 2 "/home/ubuntu/Library/data_structure/dual_segment_tree.hpp"
#include <algorithm>
#include <cassert>
#include <vector>

/**
 * @brief a dual segment tree / 双対セグメント木
 * @docs data_structure/dual_segment_tree.md
 * @tparam Monoid (commutativity is not required)
 */
template <class Monoid>
struct dual_segment_tree {
    typedef typename Monoid::value_type value_type;
    const Monoid mon;
    int n;
    std::vector<value_type> f;
    dual_segment_tree() = default;
    dual_segment_tree(int n_, const Monoid & mon_ = Monoid()) : mon(mon_) {
        n = 1; while (n < n_) n *= 2;
        f.resize(2 * n - 1, mon.unit());
    }
    value_type point_get(int i) {  // 0-based
        assert (0 <= i and i < n);
        value_type acc = mon.unit();
        for (i += n; i > 0; i /= 2) {  // 1-based
            acc = mon.mult(f[i - 1], acc);
        }
        return acc;
    }
    void range_apply(int l, int r, value_type g) {  // 0-based, [l, r)
        assert (0 <= l and l <= r and r <= n);
        range_apply(0, 0, n, l, r, g);
    }
    void range_apply(int i, int il, int ir, int l, int r, value_type g) {
        if (l <= il and ir <= r) {  // 0-based
            f[i] = mon.mult(g, f[i]);
        } else if (ir <= l or r <= il) {
            // nop
        } else {
            range_apply(2 * i + 1, il, (il + ir) / 2, 0, n, f[i]);
            range_apply(2 * i + 2, (il + ir) / 2, ir, 0, n, f[i]);
            f[i] = mon.unit();
            range_apply(2 * i + 1, il, (il + ir) / 2, l, r, g);
            range_apply(2 * i + 2, (il + ir) / 2, ir, l, r, g);
        }
    }
};
#line 2 "/home/ubuntu/Library/monoids/plus.hpp"

template <class T>
struct plus_monoid {
    typedef T value_type;
    value_type unit() const { return value_type(); }
    value_type mult(value_type a, value_type b) const { return a + b; }
};
#line 5 "main.cpp"
using namespace std;
template <typename T> istream & operator >> (istream & in, vector<T> & xs) { REP (i, xs.size()) { in >> xs[i]; } return in; }
template <typename T> ostream & operator << (ostream & out, const vector<T> & xs) { REP (i, xs.size()) { if (i) { out << ' '; } out << xs[i]; } return out; }

int main() {
    int n, q; cin >> n >> q;
    vector<int64_t> a(n); cin >> a;
    dual_segment_tree<plus_monoid<int32_t> > cnt(n);
    vector<int64_t> b(n);
    while (q --) {
        char c; int x, y; cin >> c >> x >> y;
        -- x;
        if (c == 'A') {
            b[x] -= (int64_t)y * cnt.point_get(x);
            a[x] += y;
        } else if (c == 'B') {
            cnt.range_apply(x, y, 1);
        }
    }
    REP (i, n) {
        b[i] += a[i] * cnt.point_get(i);
    }
    cout << b << endl;
    return 0;
}
0