Language: C++

#include <cstdio>
#include <vector>
#include <string>
#include <cstdint>

namespace MyInputAndOutput{
    // 入力関係 (cin)
    class user_input{
    private:
        static constexpr unsigned int sizeOfAscii = 128;
        bool isBlankChar[sizeOfAscii];
            /*  < definition of getchar >
                reference
                MacOS   : https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getchar.3.html
                Windows : https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getchar-nolock-getwchar-nolock?view=vs-2019
                Linux   : https://linux.die.net/man/3/unlocked_stdio 
                Ubuntu  : http://manpages.ubuntu.com/manpages/trusty/man3/getchar_unlocked.3posix.html
            */

            #if defined(__APPLE__)
                #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked
            #elif defined(_WIN32) || defined(_WIN64)
                #define DAGGER_GETCHAR_UNLOCKED_DAGGER _getchar_nolock
            #elif defined(__linux) 
                #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE || _BSD_SOURCE || _SVID_SOURCE
                    #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked
                #else
                    #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar
                #endif
            #else
                #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar
            #endif
    public:
        constexpr user_input(void) : isBlankChar(){
            for(unsigned int i = 0; i < sizeOfAscii; ++i) isBlankChar[i] = false;
            isBlankChar['\n'] = true; isBlankChar['\t'] = true; 
            isBlankChar[' '] = true; isBlankChar['\v'] = true;
        }
        inline const user_input& operator >> (int& int_arg) const {
            scanf("%d", &int_arg); 
            return *this;
        }
        inline const user_input& operator >> (long long int& llint_arg) const {
            scanf("%lld", &llint_arg); 
            return *this;
        }
        inline const user_input& operator >> (unsigned int& uint_arg) const {
            scanf("%u", &uint_arg); 
            return *this;
        }
        inline const user_input& operator >> (unsigned long long int& ullint_arg) const {
            scanf("%llu", &ullint_arg); 
            return *this;
        }
        inline const user_input& operator >> (unsigned long& ullint_arg) const {
            scanf("%lu", &ullint_arg); 
            return *this;
        }
        inline const user_input& operator >> (char* str_arg) const {
            scanf("%s", str_arg); 
            return *this;
        }
        inline const user_input& operator >> (char& char_arg) const {
            do{
                if((char_arg = DAGGER_GETCHAR_UNLOCKED_DAGGER()) == EOF) return *this;
            } while(isBlankChar[char_arg]);
            return *this;
        }
        inline const user_input& operator >> (std::string& str_arg) const {
            str_arg.erase();
            char c; while(true){ 
                c = DAGGER_GETCHAR_UNLOCKED_DAGGER();
                if(c == EOF) return *this;
                if(not isBlankChar[c]) break;
            }
            constexpr std::string::size_type buffer_size = 128; 
            char buffer_input[buffer_size]; std::string::size_type buffer_length = 0;
            do{
                buffer_input[buffer_length++] = c;
                if(buffer_length == buffer_size){
                    buffer_length = 0; str_arg.append(buffer_input, buffer_size);
                }
                c = DAGGER_GETCHAR_UNLOCKED_DAGGER();
            } while(c != EOF and (not isBlankChar[c]) );
            str_arg.append(buffer_input, buffer_length);
            return *this;
        }
        template <typename S, typename T>
        inline const user_input& operator >>(std::pair<S, T>& pair_arg) const{
            (*this) >> pair_arg.first >> pair_arg.second; return *this;
        }
        template <typename T>
        inline const user_input& operator >>(std::vector<T>& vec) const {
            for(T& ele : vec) (*this) >> ele; 
            return *this;
        }
        // getchar の define の解除
        #undef DAGGER_GETCHAR_UNLOCKED_DAGGER
    }; constexpr user_input cin;

    void ends(void) {putchar('\0'); }
    void endl(void) {putchar('\n'); fflush(stdout);}
    void flush(void) {fflush(stdout);}

    // 出力関係 (cout)
    class user_output{
    public:
        user_output(void){}
        inline const user_output& operator << (const int int_arg) const{
            printf("%d", int_arg); return *this;
        }
        inline const user_output& operator << (const unsigned int uint_arg) const{
            printf("%u", uint_arg); return *this;
        }
        inline const user_output& operator << (const long long int llint_arg) const {
            printf("%lld", llint_arg); return *this;
        }
        inline const user_output& operator << (const unsigned long long int ullint_arg) const {
            printf("%llu", ullint_arg); return *this;
        }
        inline const user_output& operator << (const unsigned long ulint_arg) const {
            printf("%lu", ulint_arg); return *this;
        }
        inline const user_output& operator << (const double ld_arg) const {
            printf("%.16lf", ld_arg); return *this;
        }
        inline const user_output& operator << (const long double ld_arg) const {
            printf("%.16Lf", ld_arg); return *this;
        }
        inline const user_output& operator << (const char char_arg) const {
            putchar(char_arg); return *this;
        }
        inline const user_output& operator << (const unsigned char uchar_arg) const {
            putchar(uchar_arg); return *this;
        }
        inline const user_output& operator << (const char* str_arg) const {
            fputs(str_arg, stdout); return *this;
        }
        inline const user_output& operator << (const std::string& str_arg) const {
            fputs(str_arg.c_str(), stdout); return *this;
        }
        inline const user_output& operator << (void(* const func_arg)(void)) const {
            func_arg(); return *this;
        }
        template <typename S, typename T>
        inline const user_output& operator <<(const std::pair<S, T>& pair_arg) const{
            (*this) << pair_arg.first << ' ' << pair_arg.second; return *this;
        }
        template <typename Tp_name>
        inline const user_output& operator << (const std::vector<Tp_name>& vec) const {
            const size_t size_of_vec = vec.size();
            if(size_of_vec <= 0) return *this;
            (*this) << vec[0]; 
            for(size_t index = 1; index < size_of_vec; ++index) (*this) << ' ' << vec[index];
            return *this;
        }
    } cout;

    // その他出力関数
    void binary_output(int64_t value, size_t length = 64){
        char out[length + 1];
        for(size_t i = 0; i < length; ++i) out[length - 1 - i] = ((value >> i) & 1) ? '1' : '0';
        out[length] = '\0'; puts(out);
    }
    template <typename InputType>
    void print(InputType first, InputType last, const char separate_c = ' ', const char end_c = '\n'){
        InputType it = first;
        while(true){
            MyInputAndOutput::cout << *it;
            if(++it == last){MyInputAndOutput::cout << end_c; return;}
            MyInputAndOutput::cout << separate_c;  
        }
    }
}; namespace MIO = MyInputAndOutput;

unsigned int N;
std::vector<unsigned int> data;
 
inline void build(const std::string& s){
    const unsigned int n = s.size();
    N = 1; while(N < n) N <<= 1;  data.resize(2 * N);
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1 << (s[i] - 'a');
    for(; i < N; ++i, ++j) data[j] = 0;
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1];
}
 
inline void update(unsigned int index, const char c){
    data[index += N] = 1 << (c - 'a');
    for(; index > 1; index >>= 1) data[index >> 1] = data[index] | data[index ^ 1];
}
 
inline unsigned int query(unsigned int l, unsigned int r){
    unsigned int res = 0; l += N; r += N;
    while(l < r){
        if(l & 1) res |= data[l++]; l >>= 1;
        if(r & 1) res |= data[--r]; r >>= 1;
    }
    return res;
}
 
int main(void){
    int n, q; std::string s; MIO::cin >> n >> s >> q;
    build(s);
    while(q--){
        char c; MIO::cin >> c;
        if(c == '1'){
            int i; char a; MIO::cin >> i >> a; update(--i, a);
        }
        else{
            int l, r; MIO::cin >> l >> r;
            MIO::cout << __builtin_popcount(query(--l, r)) << '\n';
        }
    }    
    return 0;
}
#include <cstdio>
#include <vector>
#include <string>
#include <cstdint>

namespace MyInputAndOutput{
      /*  < definition of getchar >
        reference
        MacOS   : https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getchar.3.html
        Windows : https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getchar-nolock-getwchar-nolock?view=vs-2019
        Linux   : https://linux.die.net/man/3/unlocked_stdio 
        Ubuntu  : http://manpages.ubuntu.com/manpages/trusty/man3/getchar_unlocked.3posix.html
    */

    #if defined(__APPLE__)
        #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked
    #elif defined(_WIN32) || defined(_WIN64)
        #define DAGGER_GETCHAR_UNLOCKED_DAGGER _getchar_nolock
    #elif defined(__linux) 
        #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE || _BSD_SOURCE || _SVID_SOURCE
            #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked
        #else
            #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar
        #endif
    #else
        #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar
    #endif
    // 入力関係 (cin)
    class user_input{
    public:
        inline const user_input& operator >> (int& int_arg) const {
            scanf("%d", &int_arg); return *this;
        }
        inline const user_input& operator >> (long long int& llint_arg) const {
            scanf("%lld", &llint_arg); return *this;
        }
        inline const user_input& operator >> (unsigned int& uint_arg) const {
            scanf("%u", &uint_arg); return *this;
        }
        inline const user_input& operator >> (unsigned long long int& ullint_arg) const {
            scanf("%llu", &ullint_arg); return *this;
        }
        inline const user_input& operator >> (unsigned long& ullint_arg) const {
            scanf("%lu", &ullint_arg); return *this;
        }
        inline const user_input& operator >> (char* str_arg) const {
            scanf("%s", str_arg); return *this;
        }
        inline const user_input& operator >> (char& char_arg) const {
            //scanf("%*c%c", &char_arg); return *this;
            do{
              if((char_arg = DAGGER_GETCHAR_UNLOCKED_DAGGER()) == EOF) return *this;
            } while(char_arg == '\n' or char_arg == ' ' or char_arg == '\t');
            return *this;
        }
        inline const user_input& operator >> (std::string& str_arg) const {
            // 計算本体
            str_arg.erase();
            char c; while(true){ 
                c = DAGGER_GETCHAR_UNLOCKED_DAGGER();
                if(c == EOF) return *this;
                if(c != '\n' and c != ' ' and c != '\t') break;
            }
            constexpr std::string::size_type buffer_size = 128; 
            char buffer_input[buffer_size]; std::string::size_type buffer_length = 0;
            do{
                buffer_input[buffer_length++] = c;
                if(buffer_length == buffer_size){
                    buffer_length = 0; str_arg.append(buffer_input, buffer_size);
                }
                c = DAGGER_GETCHAR_UNLOCKED_DAGGER();
            } while(c != EOF and c != '\n' and c != ' ' and c != '\t');
            str_arg.append(buffer_input, buffer_length);
            return *this;
        }
        template <typename S, typename T>
        inline const user_input& operator >>(std::pair<S, T>& pair_arg) const{
            (*this) >> pair_arg.first >> pair_arg.second; return *this;
        }
        template <typename T>
        inline const user_input& operator >>(std::vector<T>& vec) const {
            for(T& ele : vec) (*this) >> ele; 
            return *this;
        }
      #undef DAGGER_GETCHAR_UNLOCKED_DAGGER
    } cin;

    void ends(void) {putchar('\0'); }
    void endl(void) {putchar('\n'); fflush(stdout);}
    void flush(void) {fflush(stdout);}

    // 出力関係 (cout)
    class user_output{
    public:
        user_output(void){}
        inline const user_output& operator << (const int int_arg) const{
            printf("%d", int_arg); return *this;
        }
        inline const user_output& operator << (const unsigned int uint_arg) const{
            printf("%u", uint_arg); return *this;
        }
        inline const user_output& operator << (const long long int llint_arg) const {
            printf("%lld", llint_arg); return *this;
        }
        inline const user_output& operator << (const unsigned long long int ullint_arg) const {
            printf("%llu", ullint_arg); return *this;
        }
        inline const user_output& operator << (const unsigned long ulint_arg) const {
            printf("%lu", ulint_arg); return *this;
        }
        inline const user_output& operator << (const double ld_arg) const {
            printf("%.16lf", ld_arg); return *this;
        }
        inline const user_output& operator << (const long double ld_arg) const {
            printf("%.16Lf", ld_arg); return *this;
        }
        inline const user_output& operator << (const char char_arg) const {
            putchar(char_arg); return *this;
        }
        inline const user_output& operator << (const unsigned char uchar_arg) const {
            putchar(uchar_arg); return *this;
        }
        inline const user_output& operator << (const char* str_arg) const {
            fputs(str_arg, stdout); return *this;
        }
        inline const user_output& operator << (const std::string& str_arg) const {
            fputs(str_arg.c_str(), stdout); return *this;
        }
        inline const user_output& operator << (void(* const func_arg)(void)) const {
            func_arg(); return *this;
        }
        template <typename S, typename T>
        inline const user_output& operator <<(const std::pair<S, T>& pair_arg) const{
            (*this) << pair_arg.first << ' ' << pair_arg.second; return *this;
        }
        template <typename Tp_name>
        inline const user_output& operator << (const std::vector<Tp_name>& vec) const {
            const size_t size_of_vec = vec.size();
            if(size_of_vec <= 0) return *this;
            (*this) << vec[0]; 
            for(size_t index = 1; index < size_of_vec; ++index) (*this) << ' ' << vec[index];
            return *this;
        }
    } cout;

    // その他出力関数
    void binary_output(int64_t value, size_t length = 64){
        char out[length + 1];
        for(size_t i = 0; i < length; ++i) out[length - 1 - i] = ((value >> i) & 1) ? '1' : '0';
        out[length] = '\0'; puts(out);
    }
    template <typename InputType>
    void print(InputType first, InputType last, const char separate_c = ' ', const char end_c = '\n'){
        InputType it = first;
        while(true){
            MyInputAndOutput::cout << *it;
            if(++it == last){MyInputAndOutput::cout << end_c; return;}
            MyInputAndOutput::cout << separate_c;  
        }
    }
}; namespace MIO = MyInputAndOutput;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

unsigned int N;
std::vector<unsigned int> data;

inline void build(const std::string& s){
    const unsigned int n = s.size();
    N = 1; while(N < n) N <<= 1;  data.resize(2 * N);
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1 << (s[i] - 'a');
    for(; i < N; ++i, ++j) data[j] = 0;
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1];
}

inline void update(unsigned int index, const char c){
    data[index += N] = 1 << (c - 'a');
    for(; index > 1; index >>= 1) data[index >> 1] = data[index] | data[index ^ 1];
}

inline unsigned int query(unsigned int l, unsigned int r){
    unsigned int res = 0; l += N; r += N;
    while(l < r){
        if(l & 1) res |= data[l++]; l >>= 1;
        if(r & 1) res |= data[--r]; r >>= 1;
    }
    return res;
}

int main(void){
    int n, q; std::string s; MIO::cin >> n >> s >> q;
    build(s);
    while(q--){
        char c; MIO::cin >> c;
        if(c == '1'){
            int i; char a; MIO::cin >> i >> a; update(--i, a);
        }
        else{
            int l, r; MIO::cin >> l >> r;
            MIO::cout << __builtin_popcount(query(--l, r)) << '\n';
        }
    }    
    return 0;
}

Compiler output:
a.cc:245:11: error: redefinition of 'class MyInputAndOutput::user_input'
  245 |     class user_input{
      |           ^~~~~~~~~~
a.cc:8:11: note: previous definition of 'class MyInputAndOutput::user_input'
    8 |     class user_input{
      |           ^~~~~~~~~~
a.cc:302:7: error: conflicting declaration 'int MyInputAndOutput::cin'
  302 |     } cin;
      |       ^~~
a.cc:99:29: note: previous declaration as 'constexpr const MyInputAndOutput::user_input MyInputAndOutput::cin'
   99 |     }; constexpr user_input cin;
      |                             ^~~
a.cc:304:10: error: redefinition of 'void MyInputAndOutput::ends()'
  304 |     void ends(void) {putchar('\0'); }
      |          ^~~~
a.cc:101:10: note: 'void MyInputAndOutput::ends()' previously defined here
  101 |     void ends(void) {putchar('\0'); }
      |          ^~~~
a.cc:305:10: error: redefinition of 'void MyInputAndOutput::endl()'
  305 |     void endl(void) {putchar('\n'); fflush(stdout);}
      |          ^~~~
a.cc:102:10: note: 'void MyInputAndOutput::endl()' previously defined here
  102 |     void endl(void) {putchar('\n'); fflush(stdout);}
      |          ^~~~
a.cc:306:10: error: redefinition of 'void MyInputAndOutput::flush()'
  306 |     void flush(void) {fflush(stdout);}
      |          ^~~~~
a.cc:103:10: note: 'void MyInputAndOutput::flush()' previously defined here
  103 |     void flush(void) {fflush(stdout);}
      |          ^~~~~
a.cc:309:11: error: redefinition of 'class MyInputAndOutput::user_output'
  309 |     class user_output{
      |           ^~~~~~~~~~~
a.cc:106:11: note: previous definition of 'class MyInputAndOutput::user_output'
  106 |     class user_output{
      |           ^~~~~~~~~~~
a.cc:360:7: error: conflicting declaration 'int MyInputAndOutput::cout'
  360 |     } cout;
      |       ^~~~
a.cc:157:7: note: previous declaration as 'MyInputAndOutput::user_output MyInputAndOutput::cout'
  157 |     } cout;
      |       ^~~~
a.cc:363:10: error: redefinition of 'void MyInputAndOutput::binary_output(int64_t, size_t)'
  363 |     void binary_output(int64_t value, size_t length = 64){
      |          ^~~~~~~~~~~~~
a.cc:160:10: note: 'void MyInputAndOutput::binary_output(int64_t, size_t)' previously defined here
  160 |     void binary_output(int64_t value, size_t length = 64){
      |          ^~~~~~~~~~~~~
a.cc:369:10: error: redefinition of 'template<class InputType> void MyInputAndOutput::print(InputType, InputType, char, char)'
  369 |     void print(InputType first, InputType last, const char separate_c = ' ', const char end_c = '\n'){
      |          ^~~~~
a.cc:166:10: note: 'template<class InputType> void MyInputAndOutput::print(InputType, InputType, char, char)' previously declared here
  166 |     void print(InputType first, InputType last, const char separate_c = ' ', const char end_c = '\n'){
      |          ^~~~~
a.cc:381:14: error: redefinition of 'unsigned int N'
  381 | unsigned int N;
      |              ^
a.cc:176:14: note: 'unsigned int N' previously declared here
  176 | unsigned int N;
      |              ^
a.cc:382:27: error: redefinition of 'std::vector<unsigned int> data'
  382 | std::vector<unsigned int> data;
      |                           ^~~~
a.cc:177:27: note: 'std::vector<unsigned int> data' previously declared here
  177 | std::vector<unsigned int> data;
      |                           ^~~~
a.cc:384:13: error: redefinition of 'void build(const std::string&)'
  384 | inline void build(const std::string& s){
      |             ^~~~~
a.cc:179:13: note: 'void build(const std::string&)' previously defined here
  179 | inline void build(const std::string& s){
      |             ^~~~~
a.cc:393:13: error: redefinition of 'void update(unsigned int, char)'
  393 | inline void update(unsigned int index, const char c){
      |             ^~~~~~
a.cc:188:13: note: 'void update(unsigned int, char)' previously defined here
  188 | inline void update(unsigned int index, const char c){
      |             ^~~~~~
a.cc:398:21: error: redefinition of 'unsigned int query(unsigned int, unsigned int)'
  398 | inline unsigned int query(unsigned int l, unsigned int r){
      |                     ^~~~~
a.cc:193:21: note: 'unsigned int query(unsigned int, unsigned int)' previously defined here
  193 | inline unsigned int query(unsigned int l, unsigned int r){
      |                     ^~~~~
a.cc:407:5: error: redefinition of 'int main()'
  407 | int main(void){
      |     ^~~~
a.cc:202:5: note: 'int main()' previously defined here
  202 | int main(void){
      |     ^~~~