Language: C++

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

/*-------------------Define Start-------------------*/
typedef bool BL;                        // 布尔类型
typedef char SB;                        // 有符号1字节,8位
typedef unsigned char UB;                // 无符号1字节,8位
typedef short SW;                        // 有符号短整型,16位
typedef unsigned short UW;                // 无符号短整型,16位
typedef long SDW;                        // 有符号整型,32位
typedef unsigned long UDW;               // 无符号整型,32位
typedef long long SLL;                    // 有符号长整型,64位
typedef unsigned long long ULL;            // 无符号长整型,64位
typedef char CH;                        // 单个字符
typedef float R32;                        // 单精度浮点数
typedef double R64;                        // 双精度浮点数

#define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
#define For(i, s, t) for (register SDW i = (s); i <= (t); ++i)
#define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x7f,sizeof(a))
#define LOWBIT(x) ((x)&(-x))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define ALL(x) x.begin(),x.end()

#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl

#define lson l , mid , rt << 1 
#define rson mid + 1 , r , rt << 1 | 1

const ULL mod = 1e9 + 7;                //常用模数(可根据题目需要修改)
const ULL inf = 0x7fffffff;                //用来表示无限大
const ULL infLL = 0x7fffffffffffffffLL;    //用来表示无限大
/*-------------------Define End-------------------*/

const UDW maxN = 5e5 + 7;
SDW N, Q;
string S; 
SDW ans;

void output();

SDW st[maxN << 2];
    
inline void pushUp(SDW rt) {
    st[rt] = st[rt << 1] | st[rt << 1 | 1];
}

inline void build(SDW l, SDW r, SDW rt) {
    if(l >= r) {
        st[rt] = (1 << (S[r] - 'a'));
        return;
    }
    SDW mid = (l + r) >> 1;
    build(lson);
    build(rson);
    pushUp(rt);
}

// 单点更新 
inline void update(SDW x, SDW y, SDW l, SDW r, SDW rt) {
    if(l >= r) {
        st[rt] = y;
        return;
    }
    SDW mid = (l + r) >> 1;
    if(x <= mid) update(x, y, lson);
    else update(x, y, rson);
    pushUp(rt);
}

// 区间查询 
inline SDW query(SDW L, SDW R, SDW l, SDW r, SDW rt) {
    if(L <= l && r <= R) return st[rt];
    SDW ret = 0;
    SDW mid = (l + r) >> 1;
    
    if(L <= mid) ret |= query(L, R, lson);
    if(R > mid) ret |= query(L, R, rson);
    return ret;
}

void input(){
	cin >> N >> S >> Q;
	S = "#" + S;
	build(S, 1, N, 1);
}

void solve(){
	SDW mode;
	
	Rep(i, Q) {
		cin >> mode;
		if(mode == 1) {
			SDW x;
			CH y;
			cin >> x >> y;
			update(x, (1 << (y - 'a')), 1, N, 1);
		}
		else if(mode == 2) {
			SDW x, y;
			cin >> x >> y;
			ans = query(x, y, 1, N, 1);
			ans = __builtin_popcount(ans);
			output();
		}
	}
}

void output(){
    cout << ans << endl;
}

int main() {
    input();
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void input()':
a.cc:94:15: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'SDW' {aka 'long int'}
   94 |         build(S, 1, N, 1);
      |               ^
      |               |
      |               std::string {aka std::__cxx11::basic_string<char>}
a.cc:57:23: note:   initializing argument 1 of 'void build(SDW, SDW, SDW)'
   57 | inline void build(SDW l, SDW r, SDW rt) {
      |                   ~~~~^
a.cc: In function 'void solve()':
a.cc:100:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  100 |         Rep(i, Q) {
      |             ^
a.cc:19:37: note: in definition of macro 'Rep'
   19 | #define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
      |                                     ^