标签:clu lin mutable class 操作 define def ring +=
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define IT set<node>::iterator
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
int sum[30];
struct node{
int l,r;mutable int val;
node(int L,int R=-1,int V=0){l=L,r=R,val=V;}
bool operator <(const node &x)const{
return l<x.l;
}
};
set<node>s;
inline IT split(int pos){
IT it=s.lower_bound(node(pos));
if(it!=s.end()&&it->l==pos)return it;
--it;
int l=it->l,r=it->r,val=it->val;
s.erase(it);
s.insert(node(l,pos-1,val));
return s.insert(node(pos,r,val)).first;
}
inline void assign(int l,int r,int val){
IT itr=split(r+1),itl=split(l);
s.erase(itl,itr);
s.insert(node(l,r,val));
}
void get_sort(int l,int r){
memset(sum,0,sizeof(sum));
IT itr=split(r+1),itl=split(l),it=itl;
for(;it!=itr;++it)sum[it->val]+=it->r-it->l+1;
s.erase(itl,itr);
for(int i=1;i<=26;++i)
if(sum[i]){
s.insert(node(l,l+sum[i]-1,i));
l+=sum[i];
}
}
inline int ask(int l,int r,int val){
int ans=0;
IT itr=split(r+1),itl=split(l);
for(;itl!=itr;++itl)
if(itl->val==val)ans+=(itl->r-itl->l+1);
return ans;
}
int main(){
int n=read(),m=read();
for(int i=1;i<=n;++i){
char ch;cin>>ch;
if(ch>='a'&&ch<='z')s.insert(node(i,i,ch-'a'+1));
else s.insert(node(i,i,ch-'A'+1));
}
while(m--){
int opt=read(),l=read(),r=read(),val;
if(opt==3)get_sort(l,r);
else{
char ch;cin>>ch;
if(ch>='a'&&ch<='z')val=ch-'a'+1;
else val=ch-'A'+1;
if(opt==1)printf("%d\n",ask(l,r,val));
else assign(l,r,val);
}
}
return 0;
}
标签:clu lin mutable class 操作 define def ring +=
原文地址:https://www.cnblogs.com/PPXppx/p/11336426.html