#include #include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int op(int a, int b) { return min(a, b); } int e() { return 1 << 30; } int mapping(int f, int a) { return f + a; } int comp(int f, int g) { return f + g; } int id() { return 0; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, q; string s; cin >> n >> q >> s; vector v(n + 1, 0); rep(i, n) { v[i + 1] = v[i]; if (s[i] == '(') v[i + 1]++; else v[i + 1]--; } atcoder::lazy_segtree seg(v); while (q--) { int t; cin >> t; if (t == 1) { int x, t; cin >> x >> t; x--; if (s[x] == '(') seg.apply(x + 1, n + 1, -1); else seg.apply(x + 1, n + 1, 1); if (t == 1) s[x] = '('; else s[x] = ')'; if (s[x] != '(') seg.apply(x + 1, n + 1, -1); else seg.apply(x + 1, n + 1, 1); } else { int l, r; cin >> l >> r; l--; int L = seg.get(l); int R = seg.get(r); int M = seg.prod(l, r + 1); cout << (r - l - (L + R - 2 * M)) << endl; } } return 0; }