#include <iostream>
#include <random>
#include <chrono>
using namespace std;
const int N = 1<<19;
string t[N], S[N], s;
int l[N], r[N], Sz;
void sub1(int n, int q){
S[0] = s;
for (int i=1;i<=q;i++){
S[i] = S[i-1];
if (t[i][0] == 'q'){
int ans = 0;
for (int j=0;j<i;j++){
bool t = 1;
for (int k=l[i];k<r[i];k++)
t &= S[j][k] - '0';
ans += t;
}
cout<<ans<<'\n';
}
else
S[i][l[i]-1] ^= 1;
}
}
void sub2(int n, int q){
}
signed main(){
int n, q;
cin>>n>>q>>s;
for (int i=1;i<=q;i++){
cin>>t[i]>>l[i];
if (t[i][0] == 'q'){
cin>>r[i];
Sz |= r[i] - l[i];
}
}
if (n <= 200 and q <= 200){
sub1(n, q);
return 0;
}
if (Sz == 1){
sub2(n, q);
return 0;
}
}