結果

問題 No.789 範囲の合計
ユーザー Eki1009Eki1009
提出日時 2021-03-23 23:59:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 1,000 ms
コード長 639 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 203,872 KB
実行使用メモリ 24,808 KB
最終ジャッジ日時 2023-08-17 11:19:45
合計ジャッジ時間 5,626 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 304 ms
22,420 KB
testcase_03 AC 111 ms
4,376 KB
testcase_04 AC 313 ms
22,956 KB
testcase_05 AC 275 ms
22,296 KB
testcase_06 AC 278 ms
22,196 KB
testcase_07 AC 149 ms
4,376 KB
testcase_08 AC 256 ms
24,112 KB
testcase_09 AC 242 ms
22,920 KB
testcase_10 AC 273 ms
14,444 KB
testcase_11 AC 296 ms
24,756 KB
testcase_12 AC 289 ms
24,808 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000001;
unordered_map<int, int> B;
void add(int i, int x){
    for(i+=1;i<=MAX;i+=i&-i){
        if(!B.count(i))B[i] = 0;
        B[i] += x;
    }
}
int acc(int i){
    int res = 0;
    for(;i>0;i-=i&-i){
        if(B.count(i))res += B[i];
    }
    return res;
}
int prod(int l, int r){
    return acc(r) - acc(l);
}

int main(){
    int q;
    cin >> q;
    long long ans = 0;
    while(q--){
        int t, p, x;
        cin >> t >> p >> x;
        if(!t){
            add(p, x);
        }else{
            ans += prod(p, x+1);
        }
    }
    cout << ans << endl;
}
0