1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 1000000+100
14 #define maxm 1000+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21 int x=0,f=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
24 return x*f;
25 }
26 int n,m,block,a[maxn],b[maxn],pos[maxn],add[maxm];
27 inline void reset(int x)
28 {
29 int l=(x-1)*block+1,r=min(x*block,n);
30 for(int i=l;i<=r;i++)b[i]=a[i];
31 sort(b+l,b+r+1);
32 }
33 int find(int x,int z)
34 {
35 int l=(x-1)*block+1,r=x*block,mid;
36 while(l<=r)
37 {
38 mid=(l+r)>>1;
39 if(b[mid]>=z)r=mid-1;else l=mid+1;
40 }
41 return x*block-l+1;
42 }
43 void change(int x,int y,int z)
44 {
45 int bx=pos[x],by=pos[y];
46 if(by-bx<=1){for(int i=x;i<=y;i++)a[i]+=z;}
47 else
48 {
49 for(int i=x;i<=bx*block;i++)a[i]+=z;
50 for(int i=bx+1;i<by;i++)add[i]+=z;
51 for(int i=(by-1)*block+1;i<=y;i++)a[i]+=z;
52 }
53 reset(bx);reset(by);
54 }
55 int query(int x,int y,int z)
56 {
57 int bx=pos[x],by=pos[y],sum=0;
58 if(by-bx<=1){for(int i=x;i<=y;i++)if(a[i]+add[pos[i]]>=z)sum++;}
59 else
60 {
61 for(int i=x;i<=bx*block;i++)if(a[i]+add[bx]>=z)sum++;
62 for(int i=(by-1)*block+1;i<=y;i++)if(a[i]+add[by]>=z)sum++;
63 }
64 for(int i=bx+1;i<by;i++)sum+=find(i,z-add[i]);
65 return sum;
66 }
67 int main()
68 {
69 freopen("input.txt","r",stdin);
70 freopen("output.txt","w",stdout);
71 n=read();m=read();
72 block=floor(sqrt(n));
73 for(int i=1;i<=n;i++)
74 {
75 a[i]=read();
76 pos[i]=(i-1)/block+1;
77 }
78 for(int i=1;i<=pos[n];i++)reset(i);
79 char ch;int x,y,z;
80 while(m--)
81 {
82 ch=‘ ‘;
83 while(ch!=‘A‘&&ch!=‘M‘)ch=getchar();x=read();y=read();z=read();
84 if(ch==‘M‘)change(x,y,z);else printf("%d\n",query(x,y,z));
85 }
86 return 0;
87 }