1 #include <algorithm>
2 #include <iostream>
3 #include <cstdio>
4 #include <cmath>
5
6 using namespace std;
7
8 const int N(1005);
9 int n,q,u,v,w,tall[N*N],now[N*N];
10
11 int cnt,bel[N*N],str[N],ove[N],tag[N];
12 #define Max(a,b) (a>b?a:b)
13 #define Min(a,b) (a<b?a:b)
14 void Build()
15 {
16 int C=sqrt(n);
17 for(int i=1;i<=n;i+=C)
18 {
19 str[++cnt]=i;
20 ove[cnt]=Min(n,i+C-1);
21 sort(now+str[cnt],now+ove[cnt]+1);
22 }
23 for(int i=1;i<=cnt;i++)
24 for(int j=str[i];j<=ove[i];j++) bel[j]=i;
25 }
26 void Update(int u,int v,int x)
27 {
28 for(int i=bel[u];i<=bel[v];i++)
29 if(str[i]>=u&&ove[i]<=v) tag[i]+=x;
30 else
31 {
32 for(int j=Max(u,str[i]);j<=Min(v,ove[i]);j++)
33 now[j]+=x+tag[i];
34 sort(now+str[i],now+ove[i]+1);
35 }
36 }
37 int er(int k,int l,int r,int h)
38 {
39 int ans=0x7fffffff;
40 for(int mid;l<=r;)
41 {
42 mid=l+r>>1;
43 if(now[mid]+tag[k]>=h)
44 ans=Min(ans,mid),r=mid-1;
45 else l=mid+1;
46 }
47 return ans==0x7fffffff?0:(ove[k]-ans+1);
48 }
49 int Query(int u,int v,int h)
50 {
51 int ret=0;
52 for(int i=bel[u];i<=bel[v];i++)
53 if(str[i]>=u&&ove[i]<=v) ret+=er(i,str[i],ove[i],h);
54 else for(int j=Max(str[i],u);j<=Min(ove[i],v);j++)
55 if(tall[j]+tag[i]>=h) ret++;
56 return ret;
57 }
58
59 int main()
60 {
61 scanf("%d%d",&n,&q);
62 for(int i=1;i<=n;i++)
63 scanf("%d",tall+i),now[i]=tall[i];
64 Build();
65 for(char ch;q--;)
66 {
67 cin>>ch; scanf("%d%d%d",&u,&v,&w);
68 if(ch==‘M‘) Update(u,v,w);
69 else printf("%d\n",Query(u,v,w));
70 }
71 return 0;
72 }