結果
| 問題 | 
                            No.789 範囲の合計
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lorent_kyopro
                         | 
                    
| 提出日時 | 2021-03-12 13:13:52 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 56 ms / 1,000 ms | 
| コード長 | 1,181 bytes | 
| コンパイル時間 | 953 ms | 
| コンパイル使用メモリ | 97,080 KB | 
| 最終ジャッジ日時 | 2025-01-19 13:48:36 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
#include <atcoder/segtree>
__attribute__((constructor))
void fast_io() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using S = int;
S op(S a, S b) { return a + b; }
S e() { return 0; }
int main() {
    size_t q;
    std::cin >> q;
    std::vector<int> type(q), a(q), b(q), xs;
    for (size_t i = 0; i < q; ++i) {
        std::cin >> type[i] >> a[i] >> b[i];
        if (type[i] == 0) xs.push_back(a[i]);
    }
    std::sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    atcoder::segtree<S, op, e> seg(xs.size());
    long long ans = 0;
    for (size_t i = 0; i < q; ++i) {
        if (type[i] == 0) {
            size_t j = std::distance(xs.begin(), std::lower_bound(xs.begin(), xs.end(), a[i]));
            seg.set(j, seg.get(j) + b[i]);
        } else {
            size_t l = std::distance(xs.begin(), std::lower_bound(xs.begin(), xs.end(), a[i]));
            size_t r = std::distance(xs.begin(), std::upper_bound(xs.begin(), xs.end(), b[i]));
            ans += seg.prod(l, r);
        }
    }
    std::cout << ans << '\n';
}
            
            
            
        
            
lorent_kyopro