Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define Nmax 5000001
- using namespace std;
- int F[26];
- int n,poz,x,y;
- char c,arb[Nmax];
- void creare(int nod,int st,int dr)
- {
- if(st==dr)
- cin>>arb[st];
- else
- {
- int mij=(st+dr)/2;
- creare(2*nod,st,mij);
- creare(2*nod+1,mij+1,dr);
- }
- }
- void citire()
- {
- cin>>n;
- creare(1,1,n);
- }
- void adauga(int nod,int st,int dr)
- {
- if(st==dr)
- arb[nod]=c;
- else
- {
- int mij=(st+dr)/2;
- if(poz<=mij)
- adauga(2*nod,st,mij);
- else
- adauga(2*nod+1,mij+1,dr);
- }
- }
- void calcul(int nod,int st,int dr)
- {
- if(x<=st&&dr<=y)
- ++F[arb[st]-'a'],++F[arb[dr]-'a'];
- else
- {
- int mij=(st+dr)/2;
- if(x<=mij)
- calcul(2*nod,st,mij);
- if(mij+1<=y)
- calcul(2*nod+1,mij+1,dr);
- }
- }
- void rez()
- {
- int q,op;
- cin>>q;
- for(int i=1;i<=q;i++)
- {
- cin>>op;
- if(op==1) /// Elementul de pe pozitia poz se inlocuieste cu c
- {
- cin>>poz>>c;
- arb[poz]=c;
- adauga(1,1,n);
- }
- else /// se va afisa numarul de caractere distincte ale lui s din intervalul [a, b].
- {
- cin>>x>>y;
- for(int p=0;p<26;++p)
- F[i]=0;
- ++F[arb[x]-'a'];
- calcul(1,1,n);
- int ncd=0;
- for(int p=0;p<26;++p)
- if(F[p])
- ++ncd;
- cout<<ncd<<'\n';
- }
- }
- }
- int main()
- {
- citire();
- rez();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement