//include //------------------------------------------ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; map f; map g; class SegmentTree { int n; vector node; public: SegmentTree() { int sz = f.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, 0); } void add(int index, int val) { index += n - 1; node[index] += val; while (index > 0) { index = (index - 1) / 2; node[index] = node[index * 2 + 1] + node[index * 2 + 2]; } } int get_sum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; int vl = get_sum(a, b, k * 2 + 1, l, (l + r) / 2); int vr = get_sum(a, b, k * 2 + 2, (l + r) / 2, r); return vl + vr; } }; int main() { int Q; cin >> Q; vector p(Q), l(Q), r(Q); for (int i = 0; i < Q; i++) { cin >> p[i] >> l[i] >> r[i]; } vector d; for (int i = 0; i < Q; i++) d.push_back(l[i]), d.push_back(r[i]); sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); for (int i = 0; i < d.size(); i++) f[i] = d[i]; for (int i = 0; i < d.size(); i++) g[d[i]] = i; //SHOW_VECTOR(d); int ans = 0; SegmentTree seg; for (int i = 0; i < Q; i++) { if (p[i] == 0) { seg.add(g[l[i]], r[i]); } else { ans += seg.get_sum(g[l[i]], g[r[i]] + 1); } } cout << ans << endl; return 0; }