zhouyk0501 @ 2024-06-27 17:46:19
#include<bits/stdc++.h>
using namespace std;
inline int read(){
char ch=getchar();
int res=0,f=1;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())res=(res<<3)+(res<<1)+(ch-'0');
return res*f;
}
void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
return;
}
int arr[1000100],id[1000100];
vector<int> v[5010];
int l[5010],r[5010],lazy[5010];
main(){
int n=read(),Q=read();
for(int i=1;i<=n;i++){
arr[i]=read();
}
int sq=sqrt(n);
int L=1,R,tot=0;
for(;L<=n;L=R+1){
++tot;
R=min(tot*sq,n);
l[tot]=L;
r[tot]=R;
for(int j=L;j<=R;j++) v[tot].push_back(arr[j]),id[j]=tot;
sort(v[tot].begin(),v[tot].end());
}
while(Q--){
char op;
cin>>op;
int L=read(),R=read(),c=read();
if(op=='M'){
int LL=ceil(1.00*L/sq)*sq,RR=R/sq*sq;
for(int i=id[LL];i<=id[RR];i++) lazy[i]+=c;
for(int i=L;i<LL;i++) arr[i]+=c;
for(int i=(RR/sq+1)*sq;i<=R;i++) arr[i]+=c;
int LLL=id[L/sq*sq],RRR=id[(RR/sq+1)*sq];
v[LLL].clear();
v[RRR].clear();
for(int i=l[LLL];i<=r[LLL];i++) v[LLL].push_back(arr[i]);
for(int i=l[RRR];i<=r[RRR];i++) v[RRR].push_back(arr[i]);
sort(v[LLL].begin(),v[LLL].end());
sort(v[RRR].begin(),v[RRR].end());
}else{
int cnt=0;
int LL=ceil(1.00*L/sq)*sq,RR=R/sq*sq;
for(int i=id[LL];i<=id[RR];i++) cnt+=(v[i].size()-(lower_bound(v[i].begin(),v[i].end(),c-lazy[i])-v[i].begin()));
for(int i=L;i<LL;i++) cnt+=((arr[i]+lazy[int(i/sq)])>=c?1:0);
for(int i=(RR/sq+1)*sq;i<=R;i++) cnt+=((arr[i]+lazy[int(i/sq)])>=c?1:0);
cout<<cnt<<"\n";
}
}
}