結果

問題 No.1000 Point Add and Array Add
ユーザー trineutrontrineutron
提出日時 2020-03-02 17:44:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 2,799 ms
コンパイル使用メモリ 202,152 KB
実行使用メモリ 15,448 KB
最終ジャッジ日時 2024-04-21 22:49:08
合計ジャッジ時間 6,941 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 225 ms
13,160 KB
testcase_17 AC 188 ms
10,408 KB
testcase_18 AC 311 ms
15,448 KB
testcase_19 AC 313 ms
15,448 KB
testcase_20 AC 262 ms
15,316 KB
testcase_21 AC 321 ms
15,312 KB
testcase_22 AC 280 ms
15,192 KB
testcase_23 AC 318 ms
15,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

class segtree {
    vector<int64_t> v;
    int s;
    
    void set_inner(int x, int y, int index, int l, int r) {
        if (r <= x || y <= l) return;
        if (x <= l && r <= y) {
            v.at(index)++;
            return;
        }
        set_inner(x, y, 2 * index + 1, l, (l + r) / 2);
        set_inner(x, y, 2 * index + 2, (l + r) / 2, r);
    }
    
public:
    segtree(int n) {
        s = 1;
        while (s < n) s *= 2;
        for (int i = 0; i < 2 * s - 1; i++) {
            v.push_back(0);
        }
    }
    
    int64_t get(int x) {
        int c = x + s - 1;
        int64_t ans = 0;
        for (;;) {
            ans += v.at(c);
            if (c == 0) break;
            c = (c - 1) / 2;
        }
        return ans;
    }
    
    void set(int x, int y) {
        set_inner(x, y, 0, 0, s);
    }
    
    void print() {
        for (int i = 0; i < 2 * s - 1; i++) {
            cerr << v.at(i) << endl;
        }
    }
};

struct query {
    char c;
    int64_t x, y;
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    vector<query> v(q);
    for (int i = 0; i < q; i++) cin >> v.at(i).c >> v.at(i).x >> v.at(i).y;
    reverse(v.begin(), v.end());
    vector<int64_t> b(n);
    segtree s(n);
    for (auto t : v) {
        t.x--;
        if (t.c == 'A') {
            b.at(t.x) += s.get(t.x) * t.y;
        } else {
            s.set(t.x, t.y);
        }
    }
    for (int i = 0; i < n; i++) {
        b.at(i) += s.get(i) * a.at(i);
    }
    for (int i = 0; i < n; i++) {
        cout << b.at(i);
        if (i < n - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}
0