Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    a[c].append(i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":q=int(q);b=s[q-1];a[b].pop(bisect.bisect_left(a[b],q));bisect.insort(a[r],q);s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):d+=1
        print(d)


Fixed submission:
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":
        q=int(q)
        b=s[q-1]
        if b!=r:
            a[b].pop(bisect.bisect_left(a[b],q))
            bisect.insort(a[r],q)
            s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":q=int(q);b=s[q-1];a[b].pop(bisect.bisect_left(a[b],q));bisect.insort(a[r],q);s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)

Fixed submission:
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":
        q=int(q)
        b=s[q-1]
        if b!=r:
            a[b].pop(bisect.bisect_left(a[b],q))
            bisect.insort(a[r],q)
            s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    a[c].append(i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":q=int(q);b=s[q-1];a[b].pop(bisect.bisect_left(a[b],q));bisect.insort(a[r],q);s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):d+=1
        print(d)

Fixed submission:
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":
        q=int(q)
        b=s[q-1]
        if b!=r:
            a[b].pop(bisect.bisect_left(a[b],q))
            bisect.insort(a[r],q)
            s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
t=np.zeros((26,n+1))
for i in range(n):
    t[ord(s[i])-97][i+1]+=1
t=np.cumsum(t,axis=1)
for i in range(int(input())):
    a,b,c=map(str,input().split())
    if a=="1":
        if s[int(b)-1]!=c:
            t[ord(s[int(b)-1])-97][int(b):]-=1
            t[ord(c)-97][int(b):]+=1
            s[int(b)-1]=c
    else:
        d=0
        b,c=int(b),int(c)
        for j in range(26):
            if t[j][c]!=t[j][b-1]:
                d+=1
        print(d)

Fixed submission:
import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":
        q=int(q)
        b=s[q-1]
        if b!=r:
            a[b].pop(bisect.bisect_left(a[b],q))
            bisect.insort(a[r],q)
            s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)