#include #include #include #include #include #include #include #include #include using namespace std; using lli = long long int; using Vint = std::vector; using Vlli = std::vector; using Wint = std::vector; using Wlli = std::vector; using Vbool = std::vector; using pii = std::pair; using pll = std::pair; constexpr int MOD = 1e9 + 7; constexpr int INFi = 2e9 + 1; constexpr lli INFl = (lli)(9e18) + 1; const vector DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)}; constexpr char BR = '\n'; #define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++) #define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++) #define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--) #define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step)) #define REP(i, n) FOR(i, 0, n) #define rREP(i, n) rFOR(i, 0, (n-1)) #define vREP(ele, vec) for(auto &(ele) : (vec)) #define vREPcopy(ele, vec) for(auto (ele) : (vec)) #define SORT(A) std::sort((A).begin(), (A).end()) // 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A) #define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end()) template inline int argmin(vector vec){return min_element(vec.begin(), vec.end()) - vec.begin();} template inline int argmax(vector vec){return max_element(vec.begin(), vec.end()) - vec.begin();} template inline void chmax(T &a, T b){a = max(a, b);} template inline void chmin(T &a, T b){a = min(a, b);} inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} template inline std::string toString(T n){ if(n == 0) return "0"; std::string res = ""; if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;} while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template class SegKi{ int n; std::vector DataTree; public: // 区間の長さszから(2^k ≥ sz)となるkを求めて初期化 SegKi(int sz){ this->n = 1; while((1 << this->n) < sz) this->n++; this->DataTree.resize((1 << (this->n + 1)) -1); } // デフォルト値をしてして初期化 SegKi(int sz, T defaultValue){ this->n = 1; while((1 << this->n) < sz) this->n++; this->DataTree.resize((1 << (this->n + 1)) - 1, defaultValue); for(int i = (1 << this->n) - 2; i >= 0; i--) DataTree.at(i) = DataTree.at(2 * i + 1) + DataTree.at(2 * i + 2); } // vectorによって初期化 SegKi(vector A){ const int sz = A.size(); this->n = 1; while((1 << n) < sz) this->n++; DataTree.resize(1 << this->n); for(int i = 0; i < sz; i++) DataTree.at(i) = A.at(i); for(int i = (1 << this->n) - 2; i >= 0; i--) DataTree.at(i) = DataTree.at(2 * i + 1) + DataTree.at(2 * i + 2); } void update(int k, T value){ // A[k]の値をvalueで更新 k += (1 << this->n) - 1; DataTree.at(k) = value; while(k > 0){ k = (k - 1) / 2; DataTree.at(k) = DataTree.at(2 * k + 1) + DataTree.at(2 * k + 2); } } void add(int k, T value){ // A[k]の値をvalueで更新 k += (1 << this->n) - 1; DataTree.at(k) += value; while(k > 0){ k = (k - 1) / 2; DataTree.at(k) = DataTree.at(2 * k + 1) + DataTree.at(2 * k + 2); } } T getsum(int a, int b, T k=0, int l=0, int r=-1) { if(r < 0) r = (1 << this->n); if(b <= l or r <= a) return 0; if(a <= l and r <= b) return DataTree.at(k); T vl = getsum(a, b, 2 * k + 1, l, (l+r)/2); T vr = getsum(a, b, 2 * k + 2, (l+r)/2, r); return vl + vr; } T getValue(int j){ return DataTree.at(j + (1 << this->n) - 1); } }; int main(void){ int n, q, x, y; scanf("%d", &n); using sub_information_number = std::pair; using information = std::pair; std::vector Query(n); Vint Coordinate; REP(i, n){ scanf("\n%d %d %d", &q, &x, &y); Query.at(i) = make_pair(q == 0, make_pair(x, y)); Coordinate.push_back(x); if(q == 1) Coordinate.push_back(y); } SORT(Coordinate); COORDINATE_COMPRESSION(Coordinate); map Indexes; const int Asz = Coordinate.size(); REP(i, Asz) Indexes[Coordinate[i]] = i; lli ans = 0; SegKi Data(Asz); vREP(ele, Query){ const sub_information_number United = ele.second; if(ele.first){ int position = Indexes[United.first]; Data.add(position, United.second); } else{ int position_l = Indexes[United.first], position_r = Indexes[United.second] + 1; ans += Data.getsum(position_l, position_r); } } printf("%lld\n", ans); return 0; }