#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N,Q; cin >> N >> Q; string S; cin >> S; atcoder::fenwick_tree A(N); rep(i,N-1) if(S[i] == '(' && S[i+1] == ')') A.add(i,1); rep(i,Q){ int t; cin >> t; if(t == 2){ int l,r; cin >> l >> r; l--; int ans = A.sum(l,r-1); cout << ans << "\n"; } if(t == 1){ int p; cin >> p; p--; if(S[p] == '('){ if(p != N-1 && S[p+1] == ')') A.add(p, -1); S[p] = ')'; if(p != 0 && S[p-1] == '(') A.add(p-1, 1); } else if(S[p] == ')'){ if(p != 0 && S[p-1] == '(') A.add(p-1, -1); S[p] = '('; if(p != N-1 && S[p+1] == ')') A.add(p, 1); } } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;