結果

問題 No.789 範囲の合計
ユーザー AC2KAC2K
提出日時 2023-03-27 20:17:16
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,333 bytes
コンパイル時間 3,662 ms
コンパイル使用メモリ 258,680 KB
実行使用メモリ 5,448 KB
最終ジャッジ日時 2023-10-19 19:09:55
合計ジャッジ時間 7,004 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,348 KB
testcase_02 RE -
testcase_03 AC 40 ms
5,008 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 33 ms
5,008 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "test/yuki/No-789.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/789"

#line 2 "src/template.hpp"
#include<bits/stdc++.h>
using namespace std;
#define rep(i, N)  for(int i=0;i<(N);i++)
#define all(x) (x).begin(),(x).end()
#define popcount(x) __builtin_popcount(x)
using i128=__int128_t;
using ll = long long;
using ld = long double;
using graph = vector<vector<int>>;
using P = pair<int, int>;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;
constexpr ld eps = 1e-6;
const long double pi = acos(-1);
constexpr uint64_t MOD = 1e9 + 7;
constexpr uint64_t MOD2 = 998244353;
constexpr int dx[] = { 1,0,-1,0 };
constexpr int dy[] = { 0,1,0,-1 };
template<class T>inline void chmax(T&x,T y){if(x<y)x=y;}
template<class T>inline void chmin(T&x,T y){if(x>y)x=y;}
#line 1 "src/data-structure/BIT.hpp"
/// @brief Binary Index Tree
/// @tparam Type 要素の型
/// @tparam SumType "和が" 収まるような型
/// @docs docs/data-structure/BIT.md
template <typename Type, typename SumType = Type>
class BIT {
    int _n;
    vector<SumType> _dat;
public:
    explicit BIT(int _n) : _n(_n), _dat(_n, SumType()) {}

    inline void add(int p, Type v) {
        p++;
        for (; p <= _n; p += p & (-p)) {
            _dat[p - 1] += SumType(v);
        }
    }

    inline SumType sum(int p) {
        SumType res = 0;
        for (; p > 0; p -= p & -p) {
            res += _dat[p - 1];
        }
        return res;
    }

    inline SumType sum(int l, int r) { return sum(r) - sum(l); }
};
#line 5 "test/yuki/No-789.test.cpp"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    ll s = 0;
    vector<int> idx;
    idx.reserve(2 * n);
    vector<tuple<int, int, int>> query(n);
    for (auto& [t, a, b] : query) {
        cin >> t >> a >> b;
        idx.emplace_back(a);
        if (t == 1) idx.emplace_back(b);
    }
    sort(all(idx));
    idx.erase(unique(all(idx)), idx.end());
    BIT<ll> sg(*max_element(all(idx)) + 1);
    for (auto& [t, a, b] : query) {
        if (t == 0) {
            a = lower_bound(all(idx), a) - idx.begin();
            sg.add(a, b);
        } else {
            a = lower_bound(all(idx), a) - idx.begin();
            b = lower_bound(all(idx), b) - idx.begin();
            s += sg.sum(a, b + 1);
        }
    }
    cout << s << '\n';
}
0