#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #ifndef LOCAL #define debug(x) ; #else #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; template ostream &operator<<(ostream &out, const pair &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template ostream &operator<<(ostream &out, const vector &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 200010 /* Starry Sky Tree */ //0-index struct StarrySkyTree{ typedef int Type; int segn2; vector data, s_data; function merge; StarrySkyTree(function merge, int n): merge(merge) { for(segn2=1; segn2 struct DynamicRangeAddSegtree{ struct Node{ T val, add; Node *l, *r; Node():val(0), add(0), l(NULL), r(NULL){} ~Node() { if (l) delete l; if (r) delete r; } }; Node *root; ll segn2; DynamicRangeAddSegtree(ll n){ for(segn2=1; segn2add += c; debug(c); } else { if(node->l == NULL) node->l = new Node(); if(node->r == NULL) node->r = new Node(); T lVal = add(a, b, c, l, (l+r)/2, node->l); T rVal = add(a, b, c, (l+r)/2, r, node->r); if (l == 4 && r == 6) { debug(lVal); debug(rVal); } node->val = merge(lVal, rVal); } } return node->val + rangeAdd(l, r, l, r, node->add); } T query(ll a, ll b, ll l, ll r, Node *node){ if(r <= a || b <= l) return 0; if(a <= l && r <= b){ debug(node->val + node->add); debug(l); debug(r); return node->val + rangeAdd(a, b, l, r, node->add); } T res = 0; if (node->l) res = merge(res, query(a, b, l, (l+r)/2, node->l)); if (node->r) res = merge(res, query(a, b, (l+r)/2, r, node->r)); return res + rangeAdd(a, b, l, r, node->add); } }; template struct DynamicRangeAddRangeSumSegtree : public DynamicRangeAddSegtree { DynamicRangeAddRangeSumSegtree(ll n) : DynamicRangeAddSegtree(n) {} T merge(T a, T b) { return a + b; } T rangeAdd(ll a, ll b, ll l, ll r, T add) { if (add) { auto v = vector{a,b,l,r, add}; debug(v); debug(min(r, b) - max(a, l)); } return max(0LL, min(r, b) - max(a, l)) * add; } }; template struct DynamicRangeAddRangeMinSegtree : public DynamicRangeAddSegtree { DynamicRangeAddRangeMinSegtree(ll n) : DynamicRangeAddSegtree(n) {} T merge(T a, T b) { return min(a, b); } T rangeAdd(ll a, ll b, ll l, ll r, T add) { return add; } }; int main(){ int N = 0; scanf("%d", &N); DynamicRangeAddRangeSumSegtree seg((int)1e9 + 1); ll ans = 0; while(N--) { int c, a, b; scanf("%d%d%d", &c, &a, &b); if (c == 0) seg.add(a, a+1, b); else ans += seg.query(a, b+1); debug(ans); } debug(seg.query(0, 100000000)); printf("%lld\n", ans); return 0; }