Language: C++

#include<vector>
#include<set>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=a;i<(n);i++)
typedef long int li;

class mono{
public:
  unorder_set<char> st;
  
  // constructor
  mono(){  }
  mono(unorder_set<char> s){ st=s; }
  mono(char c){ st.insert(c); }
  // getter
  int get(){ return st.size(); }
  // addition
  mono operator+(mono m);
  // print
  void print(){for(const char& x:st) printf("%c",x);}
};


///  Segment Tree  (prototype)  ///
template<typename Monoid>
class SegTree{
  int n;
  vector<Monoid> node;
  
public:
  int parent(int a){return (a-1)/2;}
  int  left(int a) {return (a*2+1);}
  int right(int a) {return (a*2+2);}
  int leaf(int a){return (a+n-1);}
  SegTree(vector<Monoid> v);
  SegTree(int k);
  void update(int i,Monoid x);
  Monoid find(int a,int b,int i,int l,int r);
  Monoid find(int a,int b){return find(a,b,0,0,n);}
  Monoid find(int a){return node.at(leaf(a));}
  void print(){
    for(int i=0;i<2*n-1;i++){
      printf("%d: ",i);
      node.at(i).print();
      printf("\n");
    }
  }
};
///  Segment Tree  ///


int main(){
  if(df) printf("*debug mode*\n");
  int n; string s; cin >>n >>s;
  vector<mono> vec(n);
  rep(i,n) vec[i]=s.at(i);
  SegTree<mono> sgt(vec);
  if(df) sgt.print();
  int q; cin >>q;
  rep(_,q){
    int f; cin >>f;
    if(f==1){
      int i; char c; cin >>i >>c; i--;
      sgt.update(i,{c});
      if(df)printf("update\n");
    }else{
      int i,j; cin >>i >>j; i--;
      if(df)printf("find [%d %d)",i,j);
      cout << sgt.find(i,j).get() << "\n";
    }
  }
}

mono mono::operator+(mono m){
  unorder_set<char> s=m.st;
  for(char x:this->st) s.insert(x);
  return s;
}


///  Segment Tree  (main)  ///
template<typename Monoid>
SegTree<Monoid>::SegTree(vector<Monoid> v){
  int sz=v.size();
  n=1; while(n<sz)n*=2;
  node.resize(2*n-1);
  for(int i=0;i<v.size();i++){
    node.at(i+n-1)=v.at(i);
  }
  for(int i=n-2;i>=0;i--){
    node.at(i)=node.at(this->left(i))+node.at(right(i));
  }
}
template<typename Monoid>
SegTree<Monoid>::SegTree(int k){
  int sz=k;
  n=1; while(n<sz)n*=2;
  node.resize(2*n-1);
}

template<typename Monoid>
void SegTree<Monoid>::update(int i,Monoid x){
  i=this->leaf(i);
  node.at(i)=x;
  while(i>0){
    i=this->parent(i);
    node.at(i)=node.at(this->left(i))+node.at(this->right(i));
  }
}
template<typename Monoid>
Monoid SegTree<Monoid>::find(int a,int b,int i,int l,int r){
  Monoid x;
  if(df)printf(" find[%d,%d)",l,r);
  if(r<=a || b<=l)return x;
  if(a<=l && r<=b){
    if(df)printf("!");
    return node.at(i);
  }
  Monoid m1=find(a,b,this->left(i) ,l,(l+r)/2);
  Monoid m2=find(a,b,this->right(i),(l+r)/2,r);
  x=m1+m2;
  return x;
}
///  Segment Tree  ///


/// confirm df==0 ///


Compiler output:
a.cc:13:3: error: 'unorder_set' does not name a type
   13 |   unorder_set<char> st;
      |   ^~~~~~~~~~~
a.cc:17:19: error: expected ')' before '<' token
   17 |   mono(unorder_set<char> s){ st=s; }
      |       ~           ^
      |                   )
a.cc: In constructor 'mono::mono(char)':
a.cc:18:17: error: 'st' was not declared in this scope; did you mean 'std'?
   18 |   mono(char c){ st.insert(c); }
      |                 ^~
      |                 std
a.cc: In member function 'int mono::get()':
a.cc:20:21: error: 'st' was not declared in this scope; did you mean 'std'?
   20 |   int get(){ return st.size(); }
      |                     ^~
      |                     std
a.cc: In member function 'void mono::print()':
a.cc:24:34: error: 'st' was not declared in this scope; did you mean 'std'?
   24 |   void print(){for(const char& x:st) printf("%c",x);}
      |                                  ^~
      |                                  std
a.cc: In member function 'mono mono::operator+(mono)':
a.cc:79:3: error: 'unorder_set' was not declared in this scope
   79 |   unorder_set<char> s=m.st;
      |   ^~~~~~~~~~~
a.cc:79:15: error: expected primary-expression before 'char'
   79 |   unorder_set<char> s=m.st;
      |               ^~~~
a.cc:80:20: error: 'class mono' has no member named 'st'
   80 |   for(char x:this->st) s.insert(x);
      |                    ^~
a.cc:80:24: error: 's' was not declared in this scope
   80 |   for(char x:this->st) s.insert(x);
      |                        ^
a.cc:81:10: error: 's' was not declared in this scope
   81 |   return s;
      |          ^