結果

問題 No.789 範囲の合計
ユーザー kuhakukuhaku
提出日時 2021-09-27 11:40:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,598 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 207,532 KB
実行使用メモリ 48,440 KB
最終ジャッジ日時 2023-09-20 11:32:42
合計ジャッジ時間 11,904 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 994 ms
44,112 KB
testcase_03 AC 161 ms
4,376 KB
testcase_04 TLE -
testcase_05 AC 848 ms
44,384 KB
testcase_06 AC 917 ms
44,220 KB
testcase_07 AC 350 ms
4,380 KB
testcase_08 AC 956 ms
48,440 KB
testcase_09 AC 849 ms
45,268 KB
testcase_10 AC 713 ms
26,736 KB
testcase_11 AC 790 ms
44,528 KB
testcase_12 AC 788 ms
44,720 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/kuhaku/github/atcoder-lib/lib/template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < b ? a = b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return b < a ? a = b, true : false;
}
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
const double PI = acos(-1.0);
#line 3 "/home/kuhaku/kuhaku/github/atcoder-lib/lib/template/atcoder.hpp"
using ll = int64_t;
using ld = long double;
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define FORR(i, m, n) for(int i = (m)-1; i >= (n); --i)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n+1, 1)
#define all(s) (s).begin(), (s).end()
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is>>i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (auto it=v.begin(); it!=v.end(); ++it) { os<<(it==v.begin()?"":" ")<<*it; } return os;
}
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cout<<head<<'\n'; else cout<<head<<' ',co(forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cerr<<head<<'\n'; else cerr<<head<<' ',ce(forward<Tail>(tail)...);
}
template<typename T, typename... Args>
auto make_vector(T x, int arg, Args ...args) {
    if constexpr(sizeof...(args)==0) return vector<T>(arg, x); else return vector(arg,make_vector<T>(x, args...));
}
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
#line 3 "a.cpp"

template <class T, class F>
struct segment_tree {
    int N;
    const T e;
    const F op;
    unordered_map<int, T> data;

    segment_tree() {}
    segment_tree(int _n, T _e, F &&_op) : e(_e), op(_op) {
        init(_n);
    }
    segment_tree(int _n, T _e, const F &_op) : e(_e), op(_op) {
        init(_n);
    }

    const T &operator[](int i) const {
        return this->data[i + N];
    }
    T at(int k) const {
        assert(0 <= k && k < N);
        return this->data[k + N];
    }
    T get(int k) const {
        return this->at(k);
    }

    void init(int n) {
        for (N = 1; N < n; N <<= 1) {}
    }

    template <class U>
    void build(const vector<U> &v) {
        int n = v.size();
        for (int i = 0; i < n; ++i) this->data[N + i] = T(v[i]);
        for (int i = N - 1; i >= 1; --i)
            this->data[i] = this->op(this->data[i * 2], this->data[i * 2 + 1]);
    }

    void update(int k, T x) {
        this->data[k += N] = x;
        while ((k >>= 1) >= 1) {
            if (this->data.count(k * 2) && this->data.count(k * 2 + 1))
                this->data[k] = this->op(this->data[k * 2], this->data[k * 2 + 1]);
            else if (this->data.count(k * 2))
                this->data[k] = this->data[k * 2];
            else if (this->data.count(k * 2 + 1))
                this->data[k] = this->data[k * 2 + 1];
        }
    }
    void add(int k, T x) {
        this->update(k, x - this->at(k));
    }

    bool chmax(int k, T x) {
        if (this->at(k) >= x)
            return false;
        this->update(k, x);
        return true;
    }
    bool chmin(int k, T x) {
        if (this->at(k) <= x)
            return false;
        this->update(k, x);
        return true;
    }

    T query() {
        return this->data[1];
    }
    T query(int a, int b) {
        return this->query(a, b, 1, 0, this->N);
    }
    T query(int a, int b, int m, int l, int r) {
        if (a <= l && r <= b)
            return this->data.count(m) ? this->data[m] : e;
        if (r <= a || b <= l)
            return e;

        return op(this->query(a, b, m * 2, l, (l + r) >> 1),
                  this->query(a, b, m * 2 + 1, (l + r) >> 1, r));
    }
};

int main(void) {
    sonic();
    setp(10);
    auto op = [](auto a, auto b) {
        return a + b;
    };
    segment_tree st(1e9 + 1, 0L, op);

    int n;
    cin >> n;
    ll ans = 0;
    unordered_map<int, ll> mp;
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        if (!a) {
            st.update(b, mp[b] + c);
            mp[b] += c;
        } else {
            ans += st.query(b, c + 1);
        }
    }
    co(ans);

    return 0;
}
0