Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

class Monoid {
public:
    // 単位元
    int unit;
    
    Monoid() {
        // 単位元
      	unit = 0;
    }

    // 演算関数
    int calc(int a, int b) {
      return a | b;
    }
};

class SegmentTree {
public:
    // セグメント木の葉の要素数
    int n;

    // セグメント木
    vector<set<char> > tree;

    // モノイド
    Monoid mono;

    SegmentTree(vector<set<char> > &v) {
        n = 1 << (int)ceil(log2(v.size()));
        tree = vector<set<char> >(n << 1);
        for(int i = 0; i < v.size(); i++) {
            update(i, v[i]);
        }
        for(int i = v.size(); i < n; i++) {
            update(i, mono.unit);
        }
    }

    // k番目の値(0-indexed)をxに変更
    void update(int k, int x) {
        k += n;
        tree[k] = 1 << x;
        for(k = k >> 1; k > 0; k >>= 1){
            tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
        }
    }

    // [l, r)の最小値(0-indexed)を求める．
    int query(int l, int r) {
        int res = mono.unit;
        l += n;
        r += n;
        while(l < r) {
            if(l & 1) {
                res = mono.calc(res, tree[l++]);
            }
            if(r & 1) {
                res = mono.calc(res, tree[--r]);
            }
            l >>= 1;
            r >>= 1;
        }
        return res.size();
    }
    void update2(int k, int x) {
		tree[tree.size()-n+k]=1<<x;
        update(k, tree[tree.size()-n+k]);
	}
    void show() {
        int ret = 2;
        for(int i = 1; i < 2*n; i++) {
            cout << tree[i].size() << " ";
            if(i == ret - 1) {
                cout << endl;
                ret <<= 1;
            }
        }
        cout << endl;
    }
};



int main(void) {

    int n;
    string s;
    cin>>n>>s;
    int q;
    vector<int> v(n);
    rep(i,n){
      v[i]=1<<s[i];
    }
    SegmentTree st(v);
    int mode,iq,l,r;
    char c;
    scanf("%d",&q);
    rep(_,q){
        int mode;
        scanf("%d",&mode);
        if(mode==1){
            scanf("%d %c",&iq,&c);
            iq--;
            st.update2(iq,c);
        }
        if(mode==2){
            scanf("%d %d",&l,&r);
            l--;
            printf("%d\n",st.query(l,r));
        }
    }
}

Compiler output:
a.cc: In constructor 'SegmentTree::SegmentTree(std::vector<std::set<char> >&)':
a.cc:89:19: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} to 'int'
   89 |             update(i, v[i]);
      |             ~~~~~~^~~~~~~~~
a.cc:97:28: note:   initializing argument 2 of 'void SegmentTree::update(int, int)'
   97 |     void update(int k, int x) {
      |                        ~~~~^
a.cc: In member function 'void SegmentTree::update(int, int)':
a.cc:99:24: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} and 'int')
   99 |         tree[k] = 1 << x;
      |                        ^
In file included from /usr/include/c++/14/set:63,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_set.h:300:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(const std::set<_Key, _Compare, _Alloc>&) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  300 |       operator=(const set&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:300:17: note:   no known conversion for argument 1 from 'int' to 'const std::set<char>&'
  300 |       operator=(const set&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::set<_Key, _Compare, _Alloc>&&) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  304 |       operator=(set&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:17: note:   no known conversion for argument 1 from 'int' to 'std::set<char>&&'
  304 |       operator=(set&&) = default;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_set.h:318:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  318 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:318:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<char>'
  318 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:101:32: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} to 'int'
  101 |             tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:69:18: note:   initializing argument 1 of 'int Monoid::calc(int, int)'
   69 |     int calc(int a, int b) {
      |              ~~~~^
a.cc: In member function 'int SegmentTree::query(int, int)':
a.cc:112:32: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} to 'int'
  112 |                 res = mono.calc(res, tree[l++]);
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:69:25: note:   initializing argument 2 of 'int Monoid::calc(int, int)'
   69 |     int calc(int a, int b) {
      |                     ~~~~^
a.cc:115:32: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} to 'int'
  115 |                 res = mono.calc(res, tree[--r]);
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:69:25: note:   initializing argument 2 of 'int Monoid::calc(int, int)'
   69 |     int calc(int a, int b) {
      |                     ~~~~^
a.cc:120:20: error: request for member 'size' in 'res', which is of non-class type 'int'
  120 |         return res.size();
      |                    ^~~~
a.cc: In member function 'void SegmentTree::update2(int, int)':
a.cc:123:42: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} and 'int')
  123 |                 tree[tree.size()-n+k]=1<<x;
      |                                          ^
/usr/include/c++/14/bits/stl_set.h:300:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(const std::set<_Key, _Compare, _Alloc>&) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  300 |       operator=(const set&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:300:17: note:   no known conversion for argument 1 from 'int' to 'const std::set<char>&'
  300 |       operator=(const set&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::set<_Key, _Compare, _Alloc>&&) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  304 |       operator=(set&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:17: note:   no known conversion for argument 1 from 'int' to 'std::set<char>&&'
  304 |       operator=(set&&) = default;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_set.h:318:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Key = char; _Compare = std::less<char>; _Alloc = std::allocator<char>]'
  318 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:318:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<char>'
  318 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:124:15: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::set<char> >, std::set<char> >::value_type' {aka 'std::set<char>'} to 'int'
  124 |         update(k, tree[tree.size()-n+k]);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:97:28: note:   initializing argument 2 of 'void SegmentTree::update(int, int)'
   97 |     void update(int k, int x) {
      |                        ~~~~^
a.cc: In function 'int main()':
a.cc:151:21: error: no matching function for call to 'SegmentTree::SegmentTree(std::vector<int>&)'
  151 |     SegmentTree st(v);
      |                     ^
a.cc:85:5: note: candidate: 'SegmentTree::SegmentTree(std::vector<std::set<char> >&)'
   85 |     SegmentTree(vector<set<char> > &v) {
      |     ^~~~~~~~~~~
a.cc:85:37: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::set<char> >&'
   85 |     SegmentTree(vector<set<char> > &v) {
      |                 ~~~~~~~~~~~~~~~~~~~~^
a.cc:74:7: note: candidate: 'SegmentTree::SegmentTree(const SegmentTree&)'
   74 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:74:7: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const SegmentTree&'
a.cc:74:7: note: candidate: 'SegmentTree::SegmentTree(SegmentTree&&)'
a.cc:74:7: note:   no known conversion for argument 1 from 'std::vector<int>' to 'SegmentTree&&'