#include<bits/stdc++.h>
using namespace std;
int n, q, t, l, r;
deque<int> e; char c;
long long tong;

int main()
{
    cin >> n >> q;
    for(int i = 0; i < n; i++)
    {
        cin >> c;
        if(c == 'c') e.push_back(1);
        else e.push_back(0);
    }
    while(q--)
    {
        cin >> t >> l >> r;
        l--; r--;
        if(t == 1) for(int i = l; i <= r; i++) e[i] = 1-e[i];
        else
        {
            tong = 0;
            for(int i = l; i <= r; i++)
            {
                if(e[i])
                {
                    while(e[i] && i >= l)
                    {
                        i--;
                        tong += e[i];
                        e.pop_back();
                        r--;
                    }
                    tong++;
                }
            }
            cout << tong << '\n';
        }
    }
    return 0;
}
