#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } #include using namespace atcoder; using S = vector>; S op(S l, S r) { S res(4, vector(4, 1e9)); for (int i = 0; i < 4; i++) { for (int j = i; j < 4; j++) { for (int k = j; k < 4; k++) { res[i][k] = min(res[i][k], l[i][j] + r[j][k]); } } } return res; } S e() { return S(4, vector(4)); } int main() { fast_io(); int n, q; cin >> n >> q; string s; cin >> s; vector seg_data(n); for (int i = 0; i < n; i++) { seg_data[i] = S(4, vector(4, 1)); for (int j = 0; j <= s[i] - 'A'; j++) { for (int k = s[i] - 'A'; k < 4; k++) { seg_data[i][j][k] = 0; } } } segtree seg(seg_data); for (; q--;) { int com; cin >> com; if (com == 1) { int x; char c; cin >> x >> c; x--; S d(4, vector(4, 1)); for (int i = 0; i <= c - 'A'; i++) { for (int j = c - 'A'; j < 4; j++) { d[i][j] = 0; } } seg.set(x, d); } else { int l, r; cin >> l >> r; auto res = seg.prod(l - 1, r); cout << res[0][3] << "\n"; } } }