#include #include #include using namespace std; using namespace atcoder; int main() { int n, q; cin >> n >> q; string s; cin >> s; fenwick_tree ft(n - 1); for (int i = 0; i < n - 1; ++i) { if (s[i] == '(' && s[i + 1] == ')') { ft.add(i, 1); } } for (int qi = 0; qi < q; ++qi) { int type; cin >> type; if (type == 1) { int i; cin >> i; --i; if (/*i != 0 && */s[i - 1] == '(' && s[i] == ')') { ft.add(i - 1, -1); } if (/*i != n - 1 && */s[i] == '(' && s[i + 1] == ')') { ft.add(i, -1); } if (s[i] == '(') { s[i] = ')'; } else { s[i] = '('; } if (/*i != 0 && */s[i - 1] == '(' && s[i] == ')') { ft.add(i - 1, 1); } if (/*i != n - 1 && */s[i] == '(' && s[i + 1] == ')') { ft.add(i, 1); } } else { int l, r; cin >> l >> r; --l; cout << ft.sum(l, r - 1) << '\n'; } } }