using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("7");
WillReturn.Add("abcdbbd");
WillReturn.Add("6");
WillReturn.Add("2 3 6");
WillReturn.Add("1 5 z");
WillReturn.Add("2 1 1");
WillReturn.Add("1 4 a");
WillReturn.Add("1 7 d");
WillReturn.Add("2 1 7");
//3
//1
//5
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
string S = InputList[1];
var InsSegmentTree = new SegmentTree(S.Length);
for (int I = 0; I <= S.Length - 1; I++) {
InsSegmentTree.Update(I, S[I]);
}
//InsSegmentTree.DebugPrint();
foreach (string EachStr in InputList.Skip(3)) {
string[] SplitArr = EachStr.Split(' ');
if (SplitArr[0] == "1") {
int I = int.Parse(SplitArr[1]) - 1;
char C = SplitArr[2][0];
InsSegmentTree.Update(I, C);
}
if (SplitArr[0] == "2") {
int L = int.Parse(SplitArr[1]) - 1;
int R = int.Parse(SplitArr[2]) - 1;
long Result = InsSegmentTree.Query(L, R, 0);
long BitCnt = 0;
while (Result > 0) {
BitCnt += Result % 2;
Result /= 2;
}
Console.WriteLine(BitCnt);
}
}
}
}
#region SegmentTree
// SegmentTreeクラス
internal class SegmentTree
{
private long[] mTreeNodeArr;
private int UB; // 木のノードの配列のUB
private int mLeafCnt; // 葉ノードの数
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列
private struct RangeInfoDef
{
internal int StaInd;
internal int EndInd;
}
private RangeInfoDef[] mRangeInfo;
// コンストラクタ
internal SegmentTree(int pLeafCnt)
{
// 簡単のため、葉ノード数を2のべき乗に
int ArrLength = 0;
for (int I = 1; I < int.MaxValue; I *= 2) {
ArrLength += I;
mLeafCnt = I;
if (pLeafCnt < mLeafCnt) break;
}
// すべての値を初期化
UB = ArrLength - 1;
mTreeNodeArr = new long[UB + 1];
for (int I = 0; I <= UB; I++) {
mTreeNodeArr[I] = 0;
}
// ノードの添字を引数とし、範囲の開始添字と終了添字を持つ配列の作成
mRangeInfo = new RangeInfoDef[UB + 1];
for (int I = 0; I <= UB; I++) {
if (I == 0) {
RangeInfoDef WillSet1;
WillSet1.StaInd = 0;
WillSet1.EndInd = mLeafCnt - 1;
mRangeInfo[I] = WillSet1;
continue;
}
int ParentNode = DeriveParentNode(I);
RangeInfoDef ParentRangeInfo = mRangeInfo[ParentNode];
RangeInfoDef WillSet2;
int Mid = (ParentRangeInfo.StaInd + ParentRangeInfo.EndInd) / 2;
if (I % 2 == 1) { // 奇数ノードの場合
WillSet2.StaInd = ParentRangeInfo.StaInd;
WillSet2.EndInd = Mid;
}
else { // 偶数ノードの場合
WillSet2.StaInd = Mid + 1;
WillSet2.EndInd = ParentRangeInfo.EndInd;
}
mRangeInfo[I] = WillSet2;
}
for (int I = 0; I <= UB; I++) {
//Console.WriteLine("mRangeInfo[{0}] StaInd={1} EndInd={2}",
// I, mRangeInfo[I].StaInd, mRangeInfo[I].EndInd);
}
}
// 親ノードの添字を取得
private int DeriveParentNode(int pTarget)
{
return (pTarget - 1) / 2;
}
// 子ノードの添字(小さいほう)を取得
private int DeriveChildNode(int pTarget)
{
return pTarget * 2 + 1;
}
// 葉ノードの配列の添字を木の添字に変換して返す
private int DeriveTreeNode(int pLeafArrInd)
{
int BaseInd = UB - mLeafCnt + 1;
return BaseInd + pLeafArrInd;
}
// 葉ノードの配列のK番目の値にNewCharを設定
internal void Update(int pK, char pNewChar)
{
int CurrNode = DeriveTreeNode(pK);
mTreeNodeArr[CurrNode] = 1 << (pNewChar - 'a');
// 登りながら更新
while (CurrNode > 0) {
CurrNode = DeriveParentNode(CurrNode);
int ChildNode1 = DeriveChildNode(CurrNode);
int ChildNode2 = ChildNode1 + 1;
long ParentVal = 0;
ParentVal |= mTreeNodeArr[ChildNode1];
ParentVal |= mTreeNodeArr[ChildNode2];
mTreeNodeArr[CurrNode] = ParentVal;
}
}
// 開始添字と終了添字とカレントノードを引数として、ビットの論理和を返す
internal long Query(int pSearchStaInd, int pSearchEndInd, int pCurrNode)
{
int CurrNodeStaInd = mRangeInfo[pCurrNode].StaInd;
int CurrNodeEndInd = mRangeInfo[pCurrNode].EndInd;
// OverLapしてなければ、0
if (CurrNodeEndInd < pSearchStaInd || pSearchEndInd < CurrNodeStaInd)
return 0;
// 完全に含んでいれば、このノードの値
if (pSearchStaInd <= CurrNodeStaInd && CurrNodeEndInd <= pSearchEndInd)
return mTreeNodeArr[pCurrNode];
// そうでなければ、2つの子のSum
int ChildNode1 = DeriveChildNode(pCurrNode);
int ChildNode2 = ChildNode1 + 1;
long ChildVal1 = Query(pSearchStaInd, pSearchEndInd, ChildNode1);
long ChildVal2 = Query(pSearchStaInd, pSearchEndInd, ChildNode2);
return ChildVal1 | ChildVal2;
}
internal void DebugPrint()
{
for (int I = 0; I <= UB; I++) {
Console.WriteLine("mTreeNodeArr[{0}] = {1}", I, mTreeNodeArr[I]);
}
}
}
#endregion