結果

問題 No.789 範囲の合計
ユーザー Eki1009Eki1009
提出日時 2021-03-23 23:58:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 199,520 KB
最終ジャッジ日時 2025-01-19 21:20:05
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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