class BIT attr_accessor(:arr, :size) def initialize(n) @size = n @arr = Array.new(@size+1,0) end def add(i,x) i += 1 while i <= @size @arr[i] += x i += i & -i end end def sum(i) i += 1 sum = 0 while i > 0 sum += @arr[i] i &= i - 1 end sum end end n,q = gets.split.map(&:to_i) s = gets.chomp.chars bit = BIT.new(n) n.times do |i| next if i==0 if s[i] == ")" && s[i-1] == "(" bit.add(i,1) end end ans = [] q.times do query = gets.split.map(&:to_i) if query[0]==1 i = query[1]-1 if s[i] == "(" if 0 <= i-1 && s[i-1] == "(" bit.add(i,1) end if i+1 < n && s[i+1] == ")" bit.add(i+1,-1) end s[i] = ")" else if 0 <= i-1 && s[i-1] == "(" bit.add(i,-1) end if i+1 < n && s[i+1] == ")" bit.add(i+1,1) end s[i] = "(" end else l,r = query[1]-1,query[2]-1 ans << bit.sum(r) - bit.sum(l) end end puts ans