#include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f, MOD = 1000000007; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*-----------------------------------------*/ template struct BIT { BIT(int sz_) { sz = sz_ + 1; dat.assign(sz, 0); } void add(int idx, Abelian value) { while (idx < sz) { dat[idx] += value; idx += idx & -idx; } } Abelian sum(int idx) { Abelian res = 0; while (idx > 0) { res += dat[idx]; idx -= idx & -idx; } return res; } int lower_bound(Abelian value) { if (value <= 0) return 0; int res = 0, exponent = 1; while (exponent < sz) exponent <<= 1; for (int mask = exponent >> 1; mask > 0; mask >>= 1) { if (res + mask < sz && dat[res + mask] < value) { value -= dat[res + mask]; res += mask; } } return res + 1; } private: int sz; vector dat; }; int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n; cin >> n; vector q(n), l(n), r(n), x; REP(i, n) { cin >> q[i] >> l[i] >> r[i]; x.emplace_back(l[i]); if (q[i] == 1) x.emplace_back(r[i]); } sort(ALL(x)); x.erase(unique(ALL(x)), x.end()); BIT bit(x.size()); long long ans = 0; REP(i, n) { l[i] = lower_bound(ALL(x), l[i]) - x.begin(); if (q[i] == 0) { bit.add(l[i], r[i]); } else { r[i] = lower_bound(ALL(x), r[i]) - x.begin(); ans += bit.sum(r[i]) - (l[i] > 0 ? bit.sum(l[i] - 1) : 0); } } cout << ans << '\n'; return 0; }