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 # 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()) bit = BIT(n+5) for i in range(n-1): if S[i] == "(" and S[i+1] == ")": bit.add(i+1,1) 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,-1) if x != 0 and S[x-1] == "(": bit.add(x,1) elif S[x] == ")": S[x] == "(" if x != n-1 and S[x+1] == ")": bit.add(x+1,1) if x != 0 and S[x-1] == "(": bit.add(x,-1) else: _,l,r = l print(bit.sum(r)-bit.sum(l-1))