#include #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(obj) obj.begin(), obj.end() const int iINF = 1e9; const long long llINF = 1e18; const int MOD = 1e9 + 7; using namespace std; template struct SegmentTree { using F = function; int size = 1; vector node; const F f; const Monoid e; SegmentTree(int n, const F f, const Monoid &e) : f(f), e(e) { while (size < n) size <<= 1; node.assign(2 * size, e); for (int i = size - 2; i >= 0; i--) { node[i] = f(node[2 * i + 1], node[2 * i + 2]); } } SegmentTree(vector vec, const F f, const Monoid &e) : f(f), e(e) { int n = (int)vec.size(); while (size < n) size <<= 1; node.assign(2 * size, e); for (int i = 0; i < n; i++) { node[i + size - 1] = vec[i]; } for (int i = n - 2; i >= 0; i--) { node[i] = f(node[2 * i + 1], node[2 * i + 2]); } } void set(int i, const Monoid &x) { node[i + size - 1] = x; } void update(int i, const Monoid &x) { i += (size - 1); node[i] = x; while (i > 0) { i = (i - 1) / 2; node[i] = f(node[2 * i + 1], node[2 * i + 2]); } } Monoid query(int a, int b, int i = 0, int l = 0, int r = -1) { if (r < 0) r = size; if (r <= a || b <= l) return e; if (a <= l && r <= b) return node[i]; Monoid xl = query(a, b, 2 * i + 1, l, (l + r) / 2); Monoid xr = query(a, b, 2 * i + 2, (r + l) / 2, r); return f(xl, xr); } }; int main() { int N; cin >> N; vector query(N), x(N), y(N), num; REP(i, N) { cin >> query[i] >> x[i] >> y[i]; if (query[i] == 0) { num.push_back(x[i]); } else { num.push_back(x[i]); num.push_back(y[i]); } } sort(ALL(num)); num.erase(unique(ALL(num)), num.end()); long long ans = 0; SegmentTree seg( num.size(), [](long long a, long long b) { return a + b; }, 0); REP(i, N) { if (query[i] == 0) { int index = lower_bound(ALL(num), x[i]) - num.begin(); seg.update(index, y[i] + seg.query(index, index + 1)); } else { int l = lower_bound(ALL(num), x[i]) - num.begin(); int r = lower_bound(ALL(num), y[i]) - num.begin(); ans += seg.query(l, r + 1); } } cout << ans << endl; }