結果

問題 No.789 範囲の合計
ユーザー Eki1009Eki1009
提出日時 2021-03-23 23:58:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 204,932 KB
実行使用メモリ 24,932 KB
最終ジャッジ日時 2024-05-04 18:03:41
合計ジャッジ時間 7,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,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;
    int 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