N, M = gets.split(" ").map{|s| s.to_i} a = gets.split(" ").map{|s| s.to_i} ary = [] hash = {} a.each_with_index {|x, i| hash[i+1] = x ary << [x, i+1] } ary.sort! Q = gets.to_i q = [] Q.times { q << gets.split(" ").map{|s| s.to_i} } q.each {|t, x, y| if t == 1 then v = hash[x] hash[x] = v + y i = ary.bsearch_index{|z| (z <=> [v, x]) >= 0} ary = ary[0, i] + ary[i+1..-1] i = ary.bsearch_index{|z| (z <=> [v + y, x]) >= 0} if i then ary = ary[0, i] + [[v + y, x]] + ary[i..-1] else ary << [v + y, x] end elsif t == 2 then v = hash[x] hash[x] = v - y i = ary.bsearch_index{|z| (z <=> [v, x]) >= 0} ary = ary[0, i] + ary[i+1..-1] i = ary.bsearch_index{|z| (z <=> [v - y, x]) >= 0} if i then ary = ary[0, i] + [[v - y, x]] + ary[i..-1] else ary << [v - y, x] end else puts ary[-1][1] end }