import sys from sys import stdin #0-indexed , 半開区間[a,b) #calc変更で演算変更 class SegTree: def __init__(self,N,first): self.NO = 2**(N-1).bit_length() self.First = first self.data = [first] * (2*self.NO) def calc(self,l,r): return l+r def update(self,ind,x): ind += self.NO - 1 self.data[ind] = x while ind >= 0: ind = (ind - 1)//2 self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2]) def query(self,l,r): L = l + self.NO R = r + self.NO s = self.First while L < R: if R & 1: R -= 1 s = self.calc(s , self.data[R-1]) if L & 1: s = self.calc(s , self.data[L-1]) L += 1 L >>= 1 R >>= 1 return s def get(self , ind): ind += self.NO - 1 return self.data[ind] N,Q = map(int,stdin.readline().split()) S = list(stdin.readline()[:-1]) ST = SegTree(N-1,0) for i in range(N-1): if S[i] == "(" and S[i+1] == ")": ST.update(i,1) ANS = [] for loop in range(Q): query = stdin.readline()[:-1] if query[0] == "1": _,ind = map(int,query.split()) ind -= 1 if S[ind] == ")" and ind != 0 and ST.get(ind-1) == 1: ST.update(i-1,0) if S[ind] == "(" and ind != N-1 and ST.get(ind+1) == 1: ST.update(i,0) if S[ind] == "(": S[ind] = ")" else: S[ind] = "(" if S[ind] == ")" and ind != 0 and S[ind-1] == "(": ST.update(i-1,1) if S[ind] == "(" and ind != N-1 and S[ind+1] == ")": ST.update(i,1) else: _,l,r = map(int,query.split()) l -= 1 r -= 1 ANS.append(ST.query(l,r)) print ("\n".join(map(str,ANS)))