#include #include #include #define llint long long using namespace std; struct SegTree{ int size; vector seg; SegTree(){} SegTree(int size){ this->size = size; seg.resize(1<<(size+1)); } void init() { for(int i = 0; i < (1<<(size+1)); i++) seg[i] = 0; } void update(int i, llint val) { i += (1 << size); seg[i] += val; while(i > 1){ i /= 2; seg[i] = seg[i*2] + seg[i*2+1]; } } llint query(int a, int b, int k, int l, int r) { if(b < l || r < a) return 0; if(a <= l && r <= b) return seg[k]; llint lval = query(a, b, k*2, l, (l+r)/2); llint rval = query(a, b, k*2+1, (l+r)/2+1, r); return lval + rval; } llint query(int a, int b) { return query(a, b, 1, 0, (1< comp; SegTree seg(19); int main(void) { cin >> n; for(int i = 0; i < n; i++){ cin >> t[i] >> l[i] >> r[i]; } for(int i = 0; i < n; i++){ if(t[i] == 0) comp.push_back(l[i]); else comp.push_back(l[i]), comp.push_back(r[i]); } sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for(int i = 0; i < n; i++){ if(t[i] == 0) l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin(); else{ l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin(); r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin(); } } llint ans = 0; for(int i = 0; i < n; i++){ if(t[i] == 0) seg.update(l[i], r[i]); else ans += seg.query(l[i], r[i]); } cout << ans << endl; return 0; }