#include #include #include #include #include using namespace std; typedef long long ll; struct BIT{ // 1-origin vector v; int n; BIT(int _n): v(vector(_n+1, 0)), n(_n) {} ll sum(int i){ ll s = 0; while(i > 0){ s += v[i]; i -= lsb(i); } return s; } ll sum(int l, int r){ return sum(r) - sum(l-1); } void add(int i, int x){ while(i <= n){ v[i] += x; i += lsb(i); } } private: // least significant bit int lsb(int i){ return i & -i; } }; int main(){ int n; cin >> n; set s; int a[n], b[n], c[n]; for(int i = 0; i < n; i++){ cin >> a[i] >> b[i] >> c[i]; if(a[i] == 0) s.insert(b[i]); } map zip; int cur = 1; for(auto it = s.begin(); it != s.end(); it++){ zip[*it] = cur++; } BIT bit(zip.size()+1); ll ans = 0; for(int i = 0; i < n; i++){ if(a[i] == 0){ bit.add(zip[b[i]], c[i]); }else if(a[i] == 1){ auto l = zip.lower_bound(b[i]); if(l == zip.end()) continue; auto r = zip.lower_bound(c[i]); if(r == zip.end()) r--; int le = (*l).second, ri = (*r).second; if(le <= ri) ans += bit.sum(le, ri); } } cout << ans << endl; return 0; }