class BIT: def __init__(self,size): self.size = size self.tree = [0] * (size+1) def add(self,i,x): while i <= self.size: self.tree[i] += x i += i & -i return def ac(self,i): res = 0 while i > 0: res += self.tree[i] i -= i & -i return res n,q = map(int,input().split()) s = input() l = [] for i in s: if i == '(': l.append(0) else: l.append(1) bit = BIT(n) for i in range(n-1): if l[i] == 0 and l[i+1] == 1: bit.add(i+1,1) for i in range(q): t = list(map(int,input().split())) if t[0] == 1: ind = t[1]-1 l[ind] = (l[ind]+1)%2 if ind > 0: if l[ind] == 1 and l[ind-1] == 0: bit.add(ind,1) elif l[ind] == l[ind-1] == 0: bit.add(ind,-1) if ind < n-1: if l[ind] == 0 and l[ind+1] == 1: bit.add(ind+1,1) elif l[ind] == l[ind+1] == 1: bit.add(ind+1,-1) else: left,right = t[1],t[2] print(bit.ac(right-1) - bit.ac(left-1))