#include "antik.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int N = 200000;
array<int,4> segtree[(N<<2)+100];
string s;

array<int,4> merge(array<int,4> left, array<int,4> right, int mid) {
	if (!left[3]) return right;
	if (!right[3]) return left;
	if (left[3] == 1 && right[3] == 1) {
		if (s[mid] == s[mid+1]) {
			return {2, 1, 1, 2};
		}
		return {3, 2, 2, 2};
	} else if (left[3] == 1) {
		if (s[mid] == s[mid+1]) {
			return {right[0]+1, 1, right[2], right[3]+1};
		} else if (s[mid] == s[mid+2]) {
			return {right[0]+2, 2, right[2], right[3]+1};
		}
		int suff = right[2];
		if (suff == right[3]) suff++;
		return {right[0]+right[1]+1, right[1]+1, suff, right[3]+1};
	} else if (right[3] == 1) {
		if (s[mid] == s[mid+1]) {
			return {left[0]+1, left[1], 1, left[3]+1};
		} else if (s[mid-1] == s[mid+1]) {
			return {left[0]+2, left[1], 2, left[3]+1};
		}
		int pref = left[1];
		if (pref == left[3]) pref++;
		return {left[0]+left[2]+1, pref, left[2]+1, left[3]+1};
	}
	if (s[mid] == s[mid+1]) {
		return {left[0]+right[0], left[1], right[2], left[3]+right[3]};
	} else if (s[mid-1]==s[mid+1] && s[mid] == s[mid+2]) {
		return {left[0]+right[0]+1, left[1], right[2], left[3]+right[3]};
	} else if (s[mid-1]==s[mid+1]) {
		int suff = right[2];
		if (suff == right[3]) suff++;
		return {left[0]+right[0]+right[1], left[1], suff, left[3]+right[3]};
	} else if (s[mid] == s[mid+2]) {
		int pref = left[1];
		if (pref == left[3]) pref++;
		return {left[0]+right[0]+left[2], pref, right[2], left[3]+right[3]};
	}
	int pref = left[1];
	int suff = right[2];
	if (pref == left[3]) pref += right[1];
	if (suff == right[3]) suff += left[2];
	return {left[0]+right[0]+left[2]*right[1],pref,suff,left[3]+right[3]};
}
void build(int l, int r, int x = 1) {
	if (l == r){
		segtree[x]={1,1,1,1};
		return;
	}
	int m = l + r >> 1;
	build(l, m, x<<1);
	build(m+1, r, (x<<1)|1);
	segtree[x] = merge(segtree[x<<1],segtree[(x<<1)|1],m);
}
void update(int p, int l, int r, int x = 1) {
	if (l == r){
		segtree[x]={1,1,1,1};
		return;
	}
	int m = l + r >> 1;
	if (p <= m) update(p, l, m, x<<1);
	else update(p, m+1, r, (x<<1)|1);
	segtree[x] = merge(segtree[x<<1],segtree[(x<<1)|1],m);
}
array<int,4> query(int tl, int tr, int l, int r, int x = 1) {
	if (l >= tl && r <= tr) return segtree[x];
	if (l > tr || r < tl) return {0,0,0,0};
	int m = l + r >> 1;
	auto left = query(tl, tr, l, m, x<<1);
	auto right = query(tl, tr, m+1, r, (x<<1)|1);
	return merge(left, right,m);
}

int sumn, sumq;
std::vector<long long> antik(int32_t N, int32_t Q, std::string S, std::vector<int32_t> T, std::vector<int32_t> A, std::vector<int32_t> B) {
	int n = N, q = Q;
	s = S;
	sumn += n;
	sumq += q;
	assert(sumn <= 200000 && sumq <= 200000);
	for (int i = 0; i < q; ++i)
	{
		assert(1 <= T[i] && T[i] <= 2);
		if (T[i] == 1) {
			assert(1 <= A[i] && A[i] <= n);
			assert(1 <= B[i] && B[i] <= 26);
		} else {
			assert(1 <= A[i] && A[i] <= B[i] && B[i] <= n);
		}
	}
	build(0,n-1);
	vector<long long> R;
	for (int _ = 0; _ < q; _++) {
		int ty = T[_], a = A[_], b = B[_];
		if (ty == 1) {
			s[a-1]='a'+b-1;
			update(a-1,0,n-1);
			a=1;
			b=n;
		}
		R.push_back(query(a-1, b-1, 0, n-1)[0]);
	}
	return R;
}

#undef int