#include #include #include #include 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); update(root, 0, size, index, value); } T fold(const std::size_t left, const std::size_t right) const { // [left, right) assert(left < right && right <= size); return fold(root, left, right, 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 void update(std::unique_ptr& node, const std::size_t left, const std::size_t right, const std::size_t index, const T& value) { 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) { update(node->left, left, i, index, value); } else { update(node->right, i, right, index, value); } node->value = Operate(value_of_node(node->left), value_of_node(node->right)); } inline T fold(const std::unique_ptr& node, const std::size_t left, const std::size_t right, const std::size_t a, const std::size_t b) const { if (!node || right <= a || b <= left) return Identity; if (left <= a && b <= right) return node->value; const auto i = a + ((b - a) >> 1); return Operate(fold(node->left, left, right, a, i), fold(node->right, left, right, i, b)); } 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; }