Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

template <typename T>
struct SegmentTree{
    using F = function<T(T,T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;

    SegmentTree(){}
    SegmentTree(F f,T ti):f(f),ti(ti){}

    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }

    void build(const vector<T> &v){
        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 set_val(int k,T x){
        dat[k+=n]=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){ //[a,b)
        if(a>=b) return ti;
        T vl=ti,vr=ti;
        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);
    }

    template<typename C>
    int find(int st,C &check,T &acc,int k,int l,int r){
        if(l+1==r){
            acc=f(acc,dat[k]);
            return check(acc)?k-n:-1;
        }
        int m=(l+r)>>1;
        if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
        if(st<=l&&!check(f(acc,dat[k]))){
            acc=f(acc,dat[k]);
            return -1;
        }
        int vl=find(st,check,acc,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(st,check,acc,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int st,C &check){
        T acc=ti;
        return find(st,check,acc,1,0,n);
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    auto f=[](char a,char b){return a+b;};
    vc<SegmentTree<int>> seg(26,SegmentTree<int>(f,0));
    vc<vi> v(26,vi(N,0));
    string S; cin >> S;
    rep(i,N){
        v[S[i]-'a'][i]=1;
    }
    rep(i,26){
        seg[i].build(v[i]);
    }
    int Q; cin >> Q;
    rep(q,Q){
        int s; cin >> s;
        if(s==1){
            int a; char c; cin >> a >> c;
            a--;
            seg[S[a]-'a'].set_val(a,0);
            seg[c-'a'].set_val(a,1);
        } else {
            int a,b; cin >> a >> b;
            a--; b--;
            int cnt=0;
            rep(i,26){
                if(max(seg[i].query(a,b+1)>0) cnt++;
            }
            cout << cnt << "\n";
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:136:23: error: no matching function for call to 'max(bool)'
  136 |                 if(max(seg[i].query(a,b+1)>0) cnt++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:136:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'bool'
  136 |                 if(max(seg[i].query(a,b+1)>0) cnt++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:137:13: error: expected primary-expression before '}' token
  137 |             }
      |             ^
a.cc:136:53: error: expected ')' before '}' token
  136 |                 if(max(seg[i].query(a,b+1)>0) cnt++;
      |                   ~                                 ^
      |                                                     )
  137 |             }
      |             ~                                        
a.cc:137:13: error: expected primary-expression before '}' token
  137 |             }
      |             ^