class BinaryIndexedTree(): def __init__(self, n: int) -> None: self.n = 1 << (n.bit_length()) self.BIT = [0] * (self.n + 1) def build(self, init_lis: list) -> None: for i, v in enumerate(init_lis): self.add(i, v) def add(self, i: int, x: int) -> None: i += 1 while i <= self.n: self.BIT[i] += x i += i & -i def sum(self, l: int, r: int) -> int: return self._sum(r) - self._sum(l) def _sum(self, i: int) -> int: res = 0 while i > 0: res += self.BIT[i] i -= i & -i return res n, q = map(int, input().split()) s = input() pos_lis = [] brac_lis = [] for i in range(n): if i + 1 < n and s[i] == "(" and s[i + 1] == ")": pos_lis.append(1) else: pos_lis.append(0) if s[i] == "(": brac_lis.append(1) else: brac_lis.append(0) BIT = BinaryIndexedTree(n) BIT.build(pos_lis) for _ in range(q): t, *Query = map(int, input().split()) if t == 1: i = Query[0] i -= 1 if brac_lis[i] == 0: brac_lis[i] = 1 if i - 1 >= 0 and brac_lis[i - 1] == 1: BIT.add(i - 1, -1) if i + 1 < n and brac_lis[i + 1] == 0: BIT.add(i, 1) else: brac_lis[i] = 0 if i + 1 < n and brac_lis[i + 1] == 0: BIT.add(i, -1) if i - 1 >= 0 and brac_lis[i - 1] == 1: BIT.add(i - 1, 1) else: l, r = Query l -= 1; r -= 1 print(BIT.sum(l, r + 1))