Problem p02763 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
  cout << a[i] << " "
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define inf 1000000000
#define mod 1000000007

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll power(ll a, ll b) {
  ll prod = 1;
  while (b) {
    if (b & 1)
      prod = (prod * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return prod;
}
bitset<26> t[10009];
string s;
void build(int v, int l, int r) {
  if (l == r) {
    bitset<26> b(0);
    b[s[l] - 97] = 1;
    t[v] = b;
  } else {
    int tm = (l + r) / 2;
    build(2 * v, l, tm);
    build(2 * v + 1, tm + 1, r);
    t[v] = (t[2 * v] | t[2 * v + 1]);
  }
}
void update(int v, int tl, int tr, int pos, char c) {
  if (tl == pos && tr == pos) {
    bitset<26> b(0);
    b[c - 97] = 1;
    t[v] = b;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, c);
    else
      update(2 * v + 1, tm + 1, tr, pos, c);
    t[v] = (t[2 * v] | t[2 * v + 1]);
  }
}
bitset<26> query(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    bitset<26> b(0);
    return b;
  }
  if (tl == l && tr == r) {
    return t[v];
  }
  int tm = (tl + tr) / 2;
  return (query(2 * v, tl, tm, l, min(r, tm)) |
          query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  int n;
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  build(1, 0, n - 1);
  while (q--) {
    int num;
    cin >> num;
    if (num == 2) {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(1, 0, n - 1, l, r).count() << endl;
    } else {
      int idx;
      char c;
      cin >> idx >> c;
      update(1, 0, n - 1, idx - 1, c);
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a, n)                                                        \
  for (int i = 0; i < n; i++)                                                  \
  cout << a[i] << " "
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define inf 1000000000
#define mod 1000000007

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll power(ll a, ll b) {
  ll prod = 1;
  while (b) {
    if (b & 1)
      prod = (prod * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return prod;
}
bitset<26> t[2000009];
string s;
void build(int v, int l, int r) {
  if (l == r) {
    bitset<26> b(0);
    b[s[l] - 97] = 1;
    t[v] = b;
  } else {
    int tm = (l + r) / 2;
    build(2 * v, l, tm);
    build(2 * v + 1, tm + 1, r);
    t[v] = (t[2 * v] | t[2 * v + 1]);
  }
}
void update(int v, int tl, int tr, int pos, char c) {
  if (tl == pos && tr == pos) {
    bitset<26> b(0);
    b[c - 97] = 1;
    t[v] = b;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, c);
    else
      update(2 * v + 1, tm + 1, tr, pos, c);
    t[v] = (t[2 * v] | t[2 * v + 1]);
  }
}
bitset<26> query(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    bitset<26> b(0);
    return b;
  }
  if (tl == l && tr == r) {
    return t[v];
  }
  int tm = (tl + tr) / 2;
  return (query(2 * v, tl, tm, l, min(r, tm)) |
          query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  int n;
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  build(1, 0, n - 1);
  while (q--) {
    int num;
    cin >> num;
    if (num == 2) {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(1, 0, n - 1, l, r).count() << endl;
    } else {
      int idx;
      char c;
      cin >> idx >> c;
      update(1, 0, n - 1, idx - 1, c);
    }
  }
  return 0;
}