N,Q = map(int,input().split()) S = input() bit = [0] * N def add(i,x): while i <= N-1: bit[i] += x i += i & -i def getsum(i): ans = 0 while i > 0: ans += bit[i] i -= i & -i return ans l = list(S) for i in range(N-1): if l[i] == '(' and l[i+1] == ')': add(i+1,1) for _ in range(Q): t = list(map(int,input().split())) if t[0] == 2: print(getsum(t[2]-1)-getsum(t[1]-1)) else: i = t[1] if l[i-1] == '(': if i < N and l[i] == ')': add(i,-1) if i >= 2 and l[i-2] == '(': add(i-1,1) l[i-1] = ')' else: if i >= 2 and l[i-2] == '(': add(i-1,-1) if i < N and l[i] == ')': add(i,1) l[i-1] = '('