Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int MAX_N=(int)1e7+777; /// limit for array size
- int n; /// array size
- int TREE[2*MAX_N];
- string str;
- void build() /// build the tree
- {
- for(int i=n-1;i>=1;--i)
- TREE[i]=TREE[i<<1]|TREE[(i<<1)|1];
- }
- void modify(char chr,int p) /// set value at position p
- {
- --p,p+=n;
- int code=(chr-'a');
- TREE[p]=(1<<code);
- for(;p>0;p>>=1)
- TREE[p>>1]=TREE[p]|TREE[p^1];
- }
- int func(int l,int r){
- int ans=0;
- --l,--r,l+=n,r+=n,++r;
- while(l<r)
- {
- if(l&1)
- ans|=TREE[l++];
- if(r&1)
- ans|=TREE[--r];
- l>>=1,r>>=1;
- }
- return __builtin_popcount(ans);
- }
- int main()
- {
- ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- cin>>n>>str;
- for(int i=0;i<n;++i)
- TREE[i+n]=(1<<(str[i]-'a'));
- build();
- int q,a,l,r;
- char chr;
- cin>>q;
- while(q--)
- {
- cin>>a>>l;
- if(a==1)
- cin>>chr,modify(chr,l);
- else
- cin>>r,cout<<func(l,r)<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement