class SegmentTree def initialize(n) @n = 1 while @n < n do @n *= 2 end @dat = Array.new(2*@n-1, Array.new(2, -1)) end def update(k, a) i = k k += @n - 1 @dat[k] = [a, i] while k > 0 do k = (k - 1) / 2 @dat[k] = [@dat[k * 2 + 1], @dat[k * 2 + 2]].max end end def max @dat[0][1] + 1 end def dat(i) @dat[i + @n - 1][0] end end N, M = gets.split(" ").map{|s| s.to_i} a = gets.split(" ").map{|s| s.to_i} tree = SegmentTree.new(M) a.each_with_index {|x, i| tree.update(i, x) } Q = gets.to_i q = [] Q.times { q << gets.split(" ").map{|s| s.to_i} } q.each {|t, x, y| if t == 1 then tree.update(x-1, tree.dat(x-1) + y) elsif t == 2 then tree.update(x-1, tree.dat(x-1) - y) else puts tree.max end }