#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include #ifdef NyaanLocal #include "misc/timer.hpp" #endif using namespace std; int N, Q; char S[200200], a[4]; long long query(int l, int r) { int x = a[0] + (a[1] << 8) + (a[2] << 16); long long ans = 0, bns = 0, cns = 0, dns = 0, ens = 0, fns = 0, gns = 0, hns = 0; #define f(i) S[i] + (S[i + 1] << 8) + (S[i + 2] << 16) int i = 0; for (; i + 10 < r; i += 4) { bool cond0 = x == f(i + 0); bool cond1 = x == f(i + 1); bool cond2 = x == f(i + 2); bool cond3 = x == f(i + 3); ans += cond0 ? i : 0; bns += cond0 ? 1 : 0; cns += cond1 ? i + 1 : 0; dns += cond1 ? 1 : 0; ens += cond2 ? i + 2 : 0; fns += cond2 ? 1 : 0; gns += cond3 ? i + 3 : 0; hns += cond3 ? 1 : 0; } for (; i + 2 < r; i++) { bool cond = x == f(i); ans += cond ? i : 0; bns += cond ? 1 : 0; } return (ans + cns + ens + gns) - (bns + dns + fns + hns) * (l - 1); } int main() { #ifdef NyaanLocal Timer timer; #endif cin >> N >> Q >> S; while (Q--) { int cmd; cin >> cmd; if (cmd == 1) { int k; char x; cin >> k >> x; k--; S[k] = x; } else { int l, r; cin >> l >> r >> a; --l; cout << query(l, r) << "\n"; } } #ifdef NyaanLocal cerr << timer() << endl; #endif }