rt,本地是对的,在洛谷上全WA
#include<cstdio>
#include<set>
#include<cstring>
#include<cctype>
using namespace std;
struct gsrakioi{
int l,r;
mutable char v;
gsrakioi(int _l,int _r=-1,char _v='\0'):l(_l),r(_r),v(_v){}
inline bool operator<(const gsrakioi &o)const{return l<o.l;}
};
set<gsrakioi> s;
typedef set<gsrakioi>::iterator iter;
int n,m;
int buc[127];
inline iter spilt(int pos){
iter it=s.lower_bound(gsrakioi(pos));
if(it!=s.end() && it->l==pos)return it;
it--;
int l=it->l,r=it->r;char v=it->v;
s.erase(it);
s.insert(gsrakioi(l,pos-1,v));
return s.insert(gsrakioi(pos,r,v)).first;
}
inline int gsr(int l,int r,char k){
iter itr=spilt(r+1),itl=spilt(l);
int ans=0;
for(;itl!=itr;itl++)if(itl->v==k)ans+=(itl->r-itl->l+1);
return ans;
}
inline void ak(int l,int r,char v){
iter itr=spilt(r+1),itl=spilt(l);
s.erase(itl,itr);
s.insert(gsrakioi(l,r,v));
}
inline void ioi(int l,int r){
memset(buc,0,sizeof(buc));
iter itr=spilt(r+1),itl=spilt(l);
iter itl1=itl;
int pos=l;
for(;itl!=itr;itl++)buc[itl->v-'A']+=itl->r-itl->l+1;
s.erase(itl1,itr);
for(int i=0;i<26;i++){
if(buc[i])s.insert(gsrakioi(pos,pos+buc[i]-1,char(i+'A')));
pos+=buc[i];
}
}
int main(){
freopen("gsrakioi.in","r",stdin);
freopen("gsrakioi.txt","w",stdout);
scanf("%d%d",&n,&m);
// printf("%d\n",m);
getchar();
for(int i=1;i<=n;i++){
char ch=getchar();
if(islower(ch))ch=toupper(ch);
s.insert(gsrakioi(i,i,ch));
}
s.insert(gsrakioi(n+1,n+1,'\0'));
for(int i=1;i<=m;i++){
int a,x,y;
char k;
scanf("%d%d%d",&a,&x,&y);
switch(a){
case 1:getchar();k=getchar();if(islower(k))k=toupper(k);printf("%d\n",gsr(x,y,k));break;
case 2:getchar();k=getchar();if(islower(k))k=toupper(k);ak(x,y,k);break;
case 3:ioi(x,y);break;
}
}
return 0;
}