Language: C++

#include <iostream>
#include <vector>
using namespace std;

struct LazySegmentTree {
    private:
        int n;
        vector<int> node, lazy;
    
    public:
        LazySegmentTree(vector<int> v){
            int sz = (int)v.size();
            n = 1;
            while(n < sz)n *= 2;
            node.resize(2*n-1);
            lazy.resize(2*n-1, 0);

            for(int i=0; i<sz; i++)node[i+n-1] = v[i];
            for(int i=n-2; i>=0; i--)node[i] = node[i*2+1] + node[i*2+2];
        }

        void eval(int k, int l, int r){
            if(lazy[k] != 0){
                node[k] += lazy[k];
                if(r-1 > 1){
                    lazy[2*k+1] += lazy[k] / 2;
                    lazy[2*k+1] += lazy[k] / 2;
                }
                lazy[k] = 0;
            }
        }

        void add(int a, int b, int x, int k=0, int l=0, int r=-1){
            if(r < 0) r = n;
            eval(k, l, r);
            if(b <= l || r <= 1) return;

            if(a <= l && r <= b) {
                lazy[k] += (r - l) * x;
                eval(k, l, r);
            }else {
                add(a, b, x, 2*k+1, l, (l+r)/2);
                add(a, b, x, 2*k+2, (l+r)/2, r);
                node[k] = node[2*k+1] + node[2*k+2];
            }
        }

        int getsum(int a, int b, int k=0, int l=0, int r=-1) {
            if(r < 0) r = n;
            if(b <= l || r <= a) return 0;

            eval(k, l, r);
            if(a <= l && r <= b) return node[k];
            int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
            int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
            return vl + vr;
        }
}

int main(void){
    int N, Q, ibuf, lbuf, rbuf;
    cin >> N;
    vector<vector<int>> Sdash(26, vector<int>(N, 0));
    vector<LazySegmentTree> STree(26);
    char sbuf, cbuf;
    vector<int> S;
    for(int i=0; i<N; i++){
        cin >> cbuf;
        int intc = cbuf - 'a';
        S.push_back(intc);
        for(int j=0; j<26; j++){
            if(j == intc){
                Sdash[j][i] = 1;
            }else{
                Sdash[j][i] = 0;
            }
        }
    }
    for(int i=0; i<26; i++){
        STree[i] = LazySegmentTree(Sdash[i]);
    }
    cin >> Q;
    int qtype;
    for(int i=0; i<Q; i++){
        cin >> qtype;
        if(qtype == 1){
            cin >> ibuf >> cbuf;
            int intc = cbuf - 'a';
            if(S[ibuf-1] != intc){
                STree[S[ibuf-1]].add(0, N-1, -1);
                STree[intc].add(0, N-1, 1);
            }
        }else{
            cin >> lbuf >> rbuf;
            lbuf--;
            int res = 0;
            for(int i=0; i<26; i++){
                res += (STree[i].getsum(lbuf, rbuf) == 0 ? 0 : 1);
            }
            cout << res << endl;
        }
    }

    return 0;
}

Compiler output:
a.cc:58:2: error: expected ';' after struct definition
   58 | }
      |  ^
      |  ;
In file included from /usr/include/c++/14/bits/alloc_traits.h:33,
                 from /usr/include/c++/14/ext/alloc_traits.h:34,
                 from /usr/include/c++/14/bits/basic_string.h:39,
                 from /usr/include/c++/14/string:54,
                 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_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = LazySegmentTree; _Args = {}]':
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = LazySegmentTree*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = LazySegmentTree*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = LazySegmentTree*; _Size = long unsigned int; _Tp = LazySegmentTree]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1720:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(size_type) [with _Tp = LazySegmentTree; _Alloc = std::allocator<LazySegmentTree>; size_type = long unsigned int]'
 1720 |           std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1721 |                                            _M_get_Tp_allocator());
      |                                            ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:558:9:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = LazySegmentTree; _Alloc = std::allocator<LazySegmentTree>; size_type = long unsigned int; allocator_type = std::allocator<LazySegmentTree>]'
  558 |       { _M_default_initialize(__n); }
      |         ^~~~~~~~~~~~~~~~~~~~~
a.cc:64:37:   required from here
   64 |     vector<LazySegmentTree> STree(26);
      |                                     ^
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'LazySegmentTree::LazySegmentTree()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:11:9: note: candidate: 'LazySegmentTree::LazySegmentTree(std::vector<int>)'
   11 |         LazySegmentTree(vector<int> v){
      |         ^~~~~~~~~~~~~~~
a.cc:11:9: note:   candidate expects 1 argument, 0 provided
a.cc:5:8: note: candidate: 'LazySegmentTree::LazySegmentTree(const LazySegmentTree&)'
    5 | struct LazySegmentTree {
      |        ^~~~~~~~~~~~~~~
a.cc:5:8: note:   candidate expects 1 argument, 0 provided
a.cc:5:8: note: candidate: 'LazySegmentTree::LazySegmentTree(LazySegmentTree&&)'
a.cc:5:8: note:   candidate expects 1 argument, 0 provided