Language: C++

/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
template <typename M>
struct SegTree {
    using Op = function<M(const M&, const M&)>;
    M ID;   // monoid identity
    Op op;  // associative operation
    int N;  // 2^lg space, for non-commutative
    vector<M> a;

    SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
        init_space(n);
        fill(a.begin() + N, a.begin() + N + n, leaf_default);
        build();
    }

    SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
        int n = leaves.size();  // array size
        init_space(n);          // Initialize Segment Tree by ID(0)
        copy(leaves.begin(), leaves.end(), a.begin() + N);
        build();                // Build up Segment Tree.
    }

    void init_space(int n) {
        N = 1; while (N < n) N <<= 1; // assign array space
        a.assign(N << 1, ID);         // 0으로 초기화
    }

    inline void pull(int i) { a[i] = op(a[i << 1], a[i << 1 | 1]); }
    void build() { for (int i = N - 1; i >= 1; i--) pull(i); }

    //Update
    void assign(int p, M val) {
        assert(0 <= p && p < N);
        for (a[p += N] = val; p >>= 1;) pull(p);
    }

    //Query
    M query(int l, int r) const {
        assert(0 <= l && r <= N);
        M resl(ID), resr(ID);
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, a[l++]);
            if (r & 1) resr = op(a[--r], resr);
        }
        return op(resl, resr);
    }
    M query_point(int p) const {
        assert(0 <= p && p < N);
        return a[p + N];
    }
    M query_all() const { return a[1]; }
};

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> a(n);

    for (int i = 0; i < n; i++) {
        a[i] = 1 << (s[i] - 'a'); // transform to [0, 25].
    }

    SegTree<int> occur(a, 0, [](int u, int v) { return u | v; });

    int q; cin >> q; //the number of quries.
    while (q--) {
        int op; cin >> op;
        if (op == 1) { //change i-th character.
            int i; char x;
            cin >> i >> x;
            i--;
            occur.assign(i, 1 << (x - 'a'));
        }
        else {  //the number of different characters in [l, r].
            int l, r;
            cin >> l >> r;
            l--;
            cout << __builtin_popcount(occur.query(l, r)) << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Compiler output:
a.cc:41:16: error: 'function' does not name a type; did you mean 'union'?
   41 |     using Op = function<M(const M&, const M&)>;
      |                ^~~~~~~~
      |                union
a.cc:43:5: error: 'Op' does not name a type
   43 |     Op op;  // associative operation
      |     ^~
a.cc:47:43: error: 'Op' has not been declared
   47 |     SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
      |                                           ^~
a.cc:53:44: error: 'Op' has not been declared
   53 |     SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
      |                                            ^~
a.cc: In constructor 'SegTree<M>::SegTree(int, M, M, int)':
a.cc:47:62: error: class 'SegTree<M>' does not have any field named 'op'
   47 |     SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
      |                                                              ^~
a.cc: In constructor 'SegTree<M>::SegTree(std::vector<_Tp>, M, int)':
a.cc:53:63: error: class 'SegTree<M>' does not have any field named 'op'
   53 |     SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
      |                                                               ^~
a.cc: In function 'void solve()':
a.cc:100:30: error: invalid user-defined conversion from 'solve()::<lambda(int, int)>' to 'int' [-fpermissive]
  100 |     SegTree<int> occur(a, 0, [](int u, int v) { return u | v; });
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:100:30: note: candidate is: 'constexpr solve()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
  100 |     SegTree<int> occur(a, 0, [](int u, int v) { return u | v; });
      |                              ^
a.cc:100:30: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:53:47: note:   initializing argument 3 of 'SegTree<M>::SegTree(std::vector<_Tp>, M, int) [with M = int]'
   53 |     SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
      |                                            ~~~^~~
a.cc: In instantiation of 'M SegTree<M>::query(int, int) const [with M = int]':
a.cc:115:51:   required from here
  115 |             cout << __builtin_popcount(occur.query(l, r)) << '\n';
      |                                        ~~~~~~~~~~~^~~~~~
a.cc:79:33: error: 'op' was not declared in this scope
   79 |             if (l & 1) resl = op(resl, a[l++]);
      |                               ~~^~~~~~~~~~~~~~
a.cc:80:33: error: 'op' was not declared in this scope
   80 |             if (r & 1) resr = op(a[--r], resr);
      |                               ~~^~~~~~~~~~~~~~
a.cc:82:18: error: 'op' was not declared in this scope
   82 |         return op(resl, resr);
      |                ~~^~~~~~~~~~~~
a.cc: In instantiation of 'void SegTree<M>::pull(int) [with M = int]':
a.cc:71:41:   required from 'void SegTree<M>::assign(int, M) [with M = int]'
   71 |         for (a[p += N] = val; p >>= 1;) pull(p);
      |                                         ^~~~
a.cc:109:25:   required from here
  109 |             occur.assign(i, 1 << (x - 'a'));
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:65:40: error: 'op' was not declared in this scope
   65 |     inline void pull(int i) { a[i] = op(a[i << 1], a[i << 1 | 1]); }
      |                                      ~~^~~~~~~~~~~~~~~~~~~~~~~~~~