Language: C++

constexpr unsigned int InputSize = 3e6;
unsigned char Input[InputSize];
unsigned char* pointer = Input;

inline unsigned int getInt(void){
    unsigned int res = 0; while(*pointer < '0') ++pointer;
    do{
        res = 10 * res + ((*pointer) - '0');
    } while(*(++pointer) >= '0');
    return res;
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
std::array<unsigned int, 2 * SIZE> data;

inline void set(void){
    N = 1; while(N < n) N <<= 1;
    while(*pointer < 'a') ++pointer;
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j){ 
        unsigned char idx = *(pointer++) - 'a'; data[j] = 1U << idx;
    }
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
}

inline void query(void){
    while(*pointer < '0') ++pointer;
    if(*(pointer++) == '1'){
        unsigned int index = getInt() - 1;
        while(*pointer < 'a') ++pointer;
        unsigned char idx = *(pointer++) - 'a';
        data[index += N] = 1U << idx;
        while(index >>= 1) data[index] = data[index << 1] | data[(index << 1) | 1U];
    }
    else{
        unsigned int l = getInt() + N - 1, r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        printf("%u\n", __builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(unsigned char), InputSize, stdin);
    n = getInt(); set(); 
    unsigned int q = getInt();
    while(q--) query();
    return 0;
}

Compiler output:
a.cc:16:6: error: 'array' in namespace 'std' does not name a template type
   16 | std::array<unsigned int, 2 * SIZE> data;
      |      ^~~~~
a.cc:1:1: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'
  +++ |+#include <array>
    1 | constexpr unsigned int InputSize = 3e6;
a.cc: In function 'void set()':
a.cc:23:49: error: 'data' was not declared in this scope
   23 |         unsigned char idx = *(pointer++) - 'a'; data[j] = 1U << idx;
      |                                                 ^~~~
a.cc:25:29: error: 'data' was not declared in this scope
   25 |     for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
      |                             ^~~~
a.cc: In function 'void query()':
a.cc:34:9: error: 'data' was not declared in this scope
   34 |         data[index += N] = 1U << idx;
      |         ^~~~
a.cc:41:30: error: 'data' was not declared in this scope
   41 |             if(l & 1) res |= data[l++]; l >>= 1;
      |                              ^~~~
a.cc:42:30: error: 'data' was not declared in this scope
   42 |             if(r & 1) res |= data[--r]; r >>= 1;
      |                              ^~~~
a.cc:44:9: error: 'printf' was not declared in this scope
   44 |         printf("%u\n", __builtin_popcount(res));
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | constexpr unsigned int InputSize = 3e6;
a.cc: In function 'int main()':
a.cc:49:52: error: 'stdin' was not declared in this scope
   49 |     fread(Input, sizeof(unsigned char), InputSize, stdin);
      |                                                    ^~~~~
a.cc:49:52: note: 'stdin' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:49:5: error: 'fread' was not declared in this scope; did you mean 'friend'?
   49 |     fread(Input, sizeof(unsigned char), InputSize, stdin);
      |     ^~~~~
      |     friend