class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def build(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] def sum(self, i): # [0, i) の要素の総和を返す s = 0 while i>0: s += self.tree[i] i -= i & -i return s def sum_range(self,l,r): return self.sum(r)-self.sum(l) # 0 index を 1 index に変更 転倒数を求めるなら1を足していく def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i n,q = map(int,input().split()) S = list(input()) L = [] bit = BIT(n) for i in range(n): if i != n-1 and S[i] == "(" and S[i+1] == ")": L.append(1) else: L.append(0) bit.build(L) for i in range(q): L = list(map(int,input().split())) if L[0] == 1: x = L[1]-1 if S[x] == "(": S[x] == ")" if x != n-1 and S[x+1] == ")": bit.add(x,-1) if x != 0 and S[x-1] == "(": bit.add(x-1,1) elif S[x] == ")": S[x] == "(" if x != n-1 and S[x+1] == ")": bit.add(x,1) if x != 0 and S[x-1] == "(": bit.add(x-1,-1) else: _,l,r = L print(bit.sum_range(l-1,r-1))