#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include using namespace std; using namespace atcoder; struct S { int a00, a01, a02, a03, a11, a12, a13, a22, a23, a33; }; S op(S A, S B) { return S{ A.a00 + B.a00, min(A.a00 + B.a01, A.a01 + B.a11), min(A.a00 + B.a02, min(A.a01 + B.a12, A.a02 + B.a22)), min(A.a00 + B.a03, min(A.a01 + B.a13, min(A.a02 + B.a23, A.a03 + B.a33))), A.a11 + B.a11, min(A.a11 + B.a12, A.a12 + B.a22), min(A.a11 + B.a13, min(A.a12 + B.a23, A.a13 + B.a33)), A.a22 + B.a22, min(A.a22 + B.a23, A.a23 + B.a33), A.a33 + B.a33}; } S e() { return S{}; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; string s; cin >> s; vector init(n); S c2mat[]{S{0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, S{1, 0, 0, 0, 0, 0, 0, 1, 1, 1}, S{1, 1, 0, 0, 1, 0, 0, 0, 0, 1}, S{1, 1, 1, 0, 1, 1, 0, 1, 0, 0}}; segtree seg([&]() { vector init(n); for (int i = 0; i < n; i++) init[i] = c2mat[s[i] - 'A']; return init; }()); while (q--) { int type; cin >> type; if (type == 1) { int x; char c; cin >> x >> c; seg.set(x - 1, c2mat[c - 'A']); } else { int l, r; cin >> l >> r; cout << seg.prod(l - 1, r).a03 << '\n'; } } }