class BinaryIndexTree def initialize(size, init: 0) @values = Array.new(size, init) @size = size end # @param idx [Integer] # @param x [Numeric] def add(idx, x) raise 'Out of range reference' if @size <= idx idx += 1 while idx <= @size @values[idx - 1] += x idx += idx & -idx end end def sum(l, r) _sum(r) - _sum(l) end private def _sum(idx) res = 0 while idx > 0 res += @values[idx - 1] idx -= idx & -idx end res end end N = gets.to_i Q = N.times.map { gets.split.map(&:to_i) } memo = Hash.new values = [] Q.select { |t, _, _| t == 0 }.each do |t, x, y| values << x end values << Float::INFINITY values.uniq! values.sort! values.each.with_index(1) do |v, idx| memo[v] = idx end bit = BinaryIndexTree.new(N + 2) ans = 0 N.times do |i| if Q[i][0] == 0 _, x, y = Q[i] idx = memo[x] bit.add(idx, y) else _, lv, rv = Q[i] l = values.bsearch_index { |v| v >= lv } r = values.bsearch_index { |v| v > rv } l += 1 ans += bit.sum(0, r + 1) - bit.sum(0, l) end end puts ans