macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
trait Monoid {
    type T: Clone + PartialEq;
    fn identity(&self) -> Self::T;
    fn binary_operate(&self, x: &Self::T, y: &Self::T) -> Self::T;
}
struct SegmentTree<M: Monoid> {
    n: usize,
    seg: Vec<M::T>,
    monoid: M,
}
impl<M: Monoid> SegmentTree<M> {
    fn new(n: usize, monoid: M) -> SegmentTree<M> {
        let n = 1 << format!("{:b}", n - 1).len();
        let seg = vec![monoid.identity(); 2 * n - 1];
        SegmentTree {
            n: n,
            seg: seg,
            monoid: monoid,
        }
    }
    #[allow(dead_code)]
    fn from_vec(v: Vec<M::T>, monoid: M) -> SegmentTree<M> {
        let n = 1 << format!("{:b}", v.len() - 1).len();
        let mut seg = vec![monoid.identity(); 2 * n - 1];
        for (i, x) in v.into_iter().enumerate() {
            seg[i + n - 1] = x;
        }
        for i in (0..n - 1).rev() {
            seg[i] = monoid.binary_operate(&seg[2 * i + 1], &seg[2 * i + 2]);
        }
        SegmentTree {
            n: n,
            seg: seg,
            monoid: monoid,
        }
    }
    fn update(&mut self, k: usize, x: M::T) {
        let mut k = k + self.n - 1;
        self.seg[k] = x;
        while k > 0 {
            k = (k - 1) / 2;
            self.seg[k] = self
                .monoid
                .binary_operate(&self.seg[2 * k + 1], &self.seg[2 * k + 2]);
        }
    }
    fn query(&self, l: usize, r: usize) -> M::T {
        let mut l = l + self.n - 1;
        let mut r = r + self.n - 1;
        let mut res = self.monoid.identity();
        while l < r {
            if r & 1 == 0 {
                r -= 1;
                res = self.monoid.binary_operate(&res, &self.seg[r]);
            }
            if l & 1 == 0 {
                res = self.monoid.binary_operate(&res, &self.seg[l]);
                l += 1;
            }
            l = (l - 1) / 2;
            r = (r - 1) / 2;
        }
        res
    }
}
struct AnyMonoid<T: Clone, F: Fn(&T, &T) -> T> {
    id: T,
    op: F,
}
impl<T: Clone, F: Fn(&T, &T) -> T> AnyMonoid<T, F> {
    fn new(id: T, op: F) -> AnyMonoid<T, F> {
        AnyMonoid { id: id, op: op }
    }
}
impl<T: Clone + PartialEq, F: Fn(&T, &T) -> T> Monoid for AnyMonoid<T, F> {
    type T = T;
    fn identity(&self) -> T {
        self.id.clone()
    }
    fn binary_operate(&self, x: &T, y: &T) -> T {
        (self.op)(x, y)
    }
}
fn main() {
    input! { iter = iter, n, s: chars, q };
    let s = s
        .into_iter()
        .map(|x| (x as u8 - 'a' as u8) as usize)
        .collect::<Vec<_>>();
    let mut segs = vec![];
    for _i in 0..26 {
        segs.push(SegmentTree::new(n, AnyMonoid::new(false, |&x, &y| x | y)));
    }
    for i in 0..n {
        segs[s[i]].update(i, true);
    }
    for _i in 0..q {
        input_inner! { iter, x };
        if x == 1 {
            input_inner! { iter, i: usize1, c: chars };
            let c = c[0];
            for j in 0..26 {
                segs[j].update(i, false);
            }
            segs[(c as u8 - 'a' as u8) as usize].update(i, true);
        } else {
            let mut res = 0;
            input_inner! { iter, l: usize1, r };
            for j in 0..26 {
                if segs[j].query(l, r) {
                    res += 1;
                }
            }
            println!("{}", res);
        }
    }
}


Measured memory_bytes: 61172