#include #include using namespace std; using namespace atcoder; using ll = long long; const int inf = 1e6; struct S { int AA, AB, AC, AD, BB, BC, BD, CC, CD, DD; }; S op(S l, S r) { S rt; rt.AA = l.AA + r.AA; rt.AB = min(l.AA + r.AB, l.AB + r.BB); rt.AC = min({l.AA + r.AC, l.AB + r.BC, l.AC + r.CC}); rt.AD = min({l.AA + r.AD, l.AB + r.BD, l.AC + r.CD, l.AD + r.DD}); rt.BB = l.BB + r.BB; rt.BC = min(l.BB + r.BC, l.BC + r.CC); rt.BD = min({l.BB + r.BD, l.BC + r.CD, l.BD + r.DD}); rt.CC = l.CC + r.CC; rt.CD = min(l.CC + r.CD, l.CD + r.DD); rt.DD = l.DD + r.DD; return rt; } S e() { return S{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; } int main() { int N, Q; cin >> N >> Q; string S_; cin >> S_; vector v(N); for (int i = 0; i < N; i++) { if (S_[i] == 'A') { v[i] = S{0, 0, 0, 0, 1, 1, 1, 1, 1, 1}; } if (S_[i] == 'B') { v[i] = S{1, 0, 0, 0, 0, 0, 0, 1, 1, 1}; } if (S_[i] == 'C') { v[i] = S{1, 1, 0, 0, 1, 0, 0, 0, 0, 1}; } if (S_[i] == 'D') { v[i] = S{1, 1, 1, 0, 1, 1, 0, 1, 0, 0}; } } segtree seg(v); for (int i = 0; i < Q; i++) { int t; cin >> t; if (t == 1) { int x; char c; cin >> x >> c; x--; if (c == 'A') { seg.set(x, S{0, 0, 0, 0, 1, 1, 1, 1, 1, 1}); } if (c == 'B') { seg.set(x, S{1, 0, 0, 0, 0, 0, 0, 1, 1, 1}); } if (c == 'C') { seg.set(x, S{1, 1, 0, 0, 1, 0, 0, 0, 0, 1}); } if (c == 'D') { seg.set(x, S{1, 1, 1, 0, 1, 1, 0, 1, 0, 0}); } } else { int l, r; cin >> l >> r; l--; r--; cout << seg.prod(l, r + 1).AD << '\n'; } } }