#include #include #include #include template class FixPoint : private F { public: template explicit constexpr FixPoint(G&& g) : F(std::forward(g)) {} template constexpr decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; template FixPoint(F&&) -> FixPoint>; template class DynamicSegmentTree { public: explicit DynamicSegmentTree(const std::size_t size) : size(std::bit_ceil(size) << 1), root(std::make_unique(Identity)) {} void update(const std::size_t index, const T value) { assert(index < size); FixPoint([&](const auto& rec, std::unique_ptr& node, const std::size_t left, const std::size_t right) { if (!node) node = std::make_unique(Identity); if (left + 1 == right) { node->value = value; return; } const auto i = left + ((right - left) >> 1); if (index < i) { rec(node->left, left, i); } else { rec(node->right, i, right); } node->value = Operate(value_of_node(node->left), value_of_node(node->right)); })(root, 0, size); } T fold(const std::size_t left, const std::size_t right) const { // [left, right) assert(left < right && right <= size); return FixPoint([&](const auto& rec, const std::unique_ptr& node, const std::size_t l, const std::size_t r) { if (!node || right <= l || r <= left) return Identity; if (left <= l && r <= right) return node->value; const auto i = l + ((r - l) >> 1); return Operate(rec(node->left, l, i), rec(node->right, i, r)); })(root, 0, size); } private: class Node { private: friend DynamicSegmentTree; friend std::unique_ptr std::make_unique(T&&); explicit Node(const T& value) : value(value) {} std::unique_ptr left; std::unique_ptr right; T value; }; inline T value_of_node(const std::unique_ptr& node) const { return node ? node->value : Identity; } const std::size_t size; std::unique_ptr root; }; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int N; std::cin >> N; DynamicSegmentTree dst(1000000001); int64_t res = 0; for (int i = 0; i < N; i++) { int q; std::cin >> q; switch (q) { case 0: { int x, y; std::cin >> x >> y; dst.update(x, dst.fold(x, x + 1) + y); break; } case 1: { int l, r; std::cin >> l >> r; r++; res += dst.fold(l, r); } } } std::cout << res << '\n'; return 0; }