結果

問題 No.789 範囲の合計
ユーザー pekempeypekempey
提出日時 2019-02-21 08:05:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 53,760 KB
実行使用メモリ 74,496 KB
最終ジャッジ日時 2024-04-27 22:38:39
合計ジャッジ時間 6,723 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 795 ms
67,072 KB
testcase_03 AC 56 ms
6,940 KB
testcase_04 AC 740 ms
64,128 KB
testcase_05 AC 435 ms
56,576 KB
testcase_06 AC 514 ms
57,472 KB
testcase_07 AC 45 ms
6,940 KB
testcase_08 AC 345 ms
34,560 KB
testcase_09 AC 309 ms
31,616 KB
testcase_10 AC 908 ms
74,496 KB
testcase_11 AC 661 ms
71,168 KB
testcase_12 AC 623 ms
71,168 KB
testcase_13 WA -
testcase_14 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <map>

#define Z (1 << 30)
std::map<int, long long> S;

void update(int k, int v) {
    for (int i = k + 1; i <= 1000000000; i += i & -i) S[i] += v;
}

long long query(int k) {
    long long o = 0;
    for (int i = k + 1; i > 0; i -= i & -i) o += S[i];
    return o;
}

int main() {
    int N;
    scanf("%d", &N);
    long long ans = 0;
    while (N--) {
        int t;
        scanf("%d", &t);
        if (t == 0) {
            int x, y;
            scanf("%d %d", &x, &y);
            update(x, y);
        } else {
            int l, r;
            scanf("%d %d", &l, &r);
            ans += query(r) - query(l - 1);
        }
    }
    printf("%lld\n", ans);
    return 0;
}
0