Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

template <typename T>
struct SegmentTree{
    typedef function<T(T,T)> F;
    int n;
    F f;
    T unit;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(int newn,F f,T t):f(f),unit(t){
        init(newn);
    }
    SegmentTree(const vector<T> &v,F f,T t):f(f),unit(t){
        int n_ = v.size();
        init(n_);
        for(int i=0;i<n_;i++)dat[n+i]=v[i];
        for(int i=n-1;i;i--){
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
        }
    }

    void init(int n_){
        n=1;
        while(n<n_)n<<=1;
        dat.aasign(n<<1,unit);
    }
    /*void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0i<n_;i++)dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }*/
    void update(int k,T x){
        dat[k+=n]=x;
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
    T query(int a,int b){
        T vl=unit,vr=unit;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if(l&1)vl=f(vl,dat[l++]);
            if(r&1)vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

};

ll n,q;
SegmentTree<ll>seg;
string s;

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +
      (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) +
      (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) +
      (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) +
      (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) +
      (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) +
      (x & 0x00000000ffffffffUL);
  return x;
}

int main(void){
    cin>>n>>s>>q;
    auto f = [] (long long l, long long r) { return l | r; };
    seg = SegmentTree<ll>(n,f,0);
    for(ll i=0;i<n;i++){
        seg.update(i,(1LL<<s[i]-'a'));
    }
    for(ll i=0;i<q;i++){
        int x;
        cin>>x;
        if(x==1){
            ll index;
            char c;
            cin>>index>>c;
            seg.update(index-1,1LL<<(c-'a'));
        }
        else{
            ll l,r;
            cin>>l>>r;
            cout<<popcount(seg.query(l-1,r))<<endl;
        }
    }
    return 0;
}
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7

Compiler output:
a.cc:109:1: error: expected unqualified-id before numeric constant
  109 | 7
      | ^
a.cc: In instantiation of 'void SegmentTree<T>::init(int) [with T = long long int]':
a.cc:26:9:   required from 'SegmentTree<T>::SegmentTree(int, F, T) [with T = long long int; F = std::function<long long int(long long int, long long int)>]'
   26 |         init(newn);
      |         ^~~~
a.cc:88:32:   required from here
   88 |     seg = SegmentTree<ll>(n,f,0);
      |                                ^
a.cc:40:13: error: 'class std::vector<long long int, std::allocator<long long int> >' has no member named 'aasign'; did you mean 'assign'?
   40 |         dat.aasign(n<<1,unit);
      |         ~~~~^~~~~~
      |         assign