結果

問題 No.1000 Point Add and Array Add
ユーザー merom686merom686
提出日時 2020-02-28 21:49:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 78,068 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-21 18:19:11
合計ジャッジ時間 3,403 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 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 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 64 ms
6,528 KB
testcase_17 AC 53 ms
5,376 KB
testcase_18 AC 89 ms
7,040 KB
testcase_19 AC 90 ms
7,168 KB
testcase_20 AC 81 ms
7,168 KB
testcase_21 AC 86 ms
7,040 KB
testcase_22 AC 88 ms
7,168 KB
testcase_23 AC 88 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    BIT bt(n + 1);

    for (int h = 0; h < q; h++) {
        char c;
        int x, y;
        cin >> c >> x >> y;
        x--;

        if (c == 'A') {
            a[x] += y;
            b[x] += (ll)y * bt.sum(x + 1);

        } else {
            bt.add(x, +1);
            bt.add(y, -1);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << a[i] * bt.sum(i + 1) - b[i] << " \n"[i == n - 1];
    }

    return 0;
}
0