#include #include using namespace std; using ll = long long; // 答え, )の個数,(の個数 using S = tuple; constexpr S op(S lhs, S rhs){ auto [Lcnt, LL, LR] = lhs; auto [Rcnt, RL, RR] = rhs; int mn = min(LR, RL); // cerr << Lcnt + Rcnt + 2 * mn << " " << LL + RL - mn << " " << LR + RR - mn << endl; return make_tuple(Lcnt + Rcnt + 2 * mn, LL + RL - mn, LR + RR - mn); } constexpr S e(){return make_tuple(0, 0, 0);} int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector tmp(n); string s; cin >> s; for(int i = 0; i < n; i++){ if(s[i] == '(') get<2>(tmp[i]) = 1; else get<1>(tmp[i]) = 1; } atcoder::segtree seg(tmp); cerr << "\n"; while(q--){ int cmd; cin >> cmd; if(cmd == 1){ int p, v; cin >> p >> v; p--; if(v == 2) seg.set(p, make_tuple(0, 1, 0)); else seg.set(p, make_tuple(0, 0, 1)); }else{ int l, r; cin >> l >> r; cout << get<0>(seg.prod(l - 1, r)) << '\n'; } } }