#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair PII; typedef vector VI; typedef vector VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i=0;i<(int)(n);++i) template class BIT { private: int n; vector bit; public: void add(int i,T x){ i++; while(i < n) bit[i] += x, i += i & -i;} T sum(int i){ i++; T s = 0; while(i>0) s += bit[i], i -= i & -i; return s;} BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //初期値がすべて0の場合 BIT(vector& v){ n = (int)v.size()+1; bit.resize(n, 0); rep(i,n-1) add(i,v[i]);} void print(){ rep(i,n-1)cout<> n; vector a(n),b(n),c(n); rep(i,n)cin >> a[i] >> b[i] >> c[i]; setst; rep(i,n){ if(a[i]==0){ st.insert(b[i]); }else{ st.insert(b[i]); st.insert(c[i]); } } map mp; int cc = 1; for(auto x:st){ mp[x] = cc; cc++; } rep(i,n){ if(a[i]==0){ b[i] = mp[b[i]]; }else{ b[i] = mp[b[i]]; c[i] = mp[c[i]]; } } BIT bit(200010); ll ans =0; rep(i,n){ if(a[i]==0){ bit.add(b[i],c[i]); }else{ ans += bit.sum(c[i])-bit.sum(b[i]-1); } } cout << ans << endl; return 0; }