#include #include #include #include #include #include #include #include template class DynamicSegmentTree { public: explicit DynamicSegmentTree(const std::size_t size) : size(std::bit_ceil(size) << 1) {} void update(const std::size_t index, const T value) { assert(index < size); nodes[index + size] = value; for (std::size_t i = (index + size) >> 1; i > 0; i >>= 1) { nodes[i] = Operate(value_of_index(i << 1), value_of_index((i << 1) | 1)); } } T fold(const std::size_t left, const std::size_t right) const { // [left, right) assert(left < right && right <= size); T x = identity; T y = identity; for (std::size_t l = left + size, r = right + size; l < r; l >>= 1, r >>= 1) { if (l % 2 != 0) x = Operate(x, value_of_index(l++)); if (r % 2 != 0) y = Operate(value_of_index(--r), y); } return Operate(x, y); } private: class Hash { public: std::size_t operator()(const std::size_t x) const { std::uint64_t res = static_cast(x) + seed + 0x9e3779b97f4a7c15; res = (res ^ (res >> 30)) * 0xbf58476d1ce4e5b9; res = (res ^ (res >> 27)) * 0x94d049bb133111eb; return static_cast(res ^ (res >> 31)); } private: static inline const std::uint64_t seed = static_cast(std::random_device()()); }; T value_of_index(std::size_t index) const { if (const auto it = nodes.find(index); it != nodes.end()) return it->second; return identity; } const std::size_t size; __gnu_pbds::gp_hash_table nodes; }; using namespace std; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; DynamicSegmentTree dst(1000000001); int64_t res = 0; for (int i = 0; i < N; i++) { int q; cin >> q; switch (q) { case 0: { int x, y; cin >> x >> y; dst.update(x, dst.fold(x, x + 1) + y); break; } case 1: { int l, r; cin >> l >> r; r++; res += dst.fold(l, r); } } } cout << res << '\n'; return 0; }