1 #include<cstdio>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstring>
5 const int maxn=1010000;
6 struct aa{int num,tag,h,block;}a[maxn];
7 int c[maxn];
8 int mid,b[maxn],n,q,tot,l,r,w;
9 using namespace std;
10 void add(int l,int r,int w){//这里写毁了
11 int zuo=a[l].h,you=a[r].h;
12 if (a[l].block*mid>=r) {for (int i=l;i<=r;i++) a[i].num+=w;
13 for (int i=(a[zuo].block-1)*mid+1;i<=a[zuo].block*mid;i++) c[i]=a[i].num;
14 sort(c+(a[l].block-1)*mid+1,c+a[l].block*mid+1);return;}
15 for (int i=l;i<=a[l].block*mid;i++)a[i].num+=w;
16 for (int i=(a[zuo].block-1)*mid+1;i<=a[zuo].block*mid;i++) c[i]=a[i].num;
17 sort(c+(a[l].block-1)*mid+1,c+a[l].block*mid+1);
18 for(int i=(a[r].block-1)*mid+1;i<=r;i++) a[i].num+=w;
19 for (int i=(a[you].block-1)*mid+1;i<=a[you].block*mid;i++) c[i]=a[i].num;
20 sort(c+(a[r].block-1)*mid+1,c+a[r].block*mid+1);
21 for (int i=a[l].block+1;i<=a[r].block-1;i++)
22 a[(i-1)*mid+1].tag+=w;
23 }
24
25 int find1(int l,int r,int c){
26 for (int i=l;i<=r;i++) b[i]=a[i].num; b[r+1]=0;
27 sort(b+l,b+r+1);
28 int x=lower_bound(b+l,b+r+1,c)-b;
29 return r-x+1;
30 }
31
32 int find2(int l,int r,int d){
33 int x=lower_bound(c+l,c+r+1,d)-c;
34 return r-x+1;
35 }
36
37 int query(int l,int r,int d){
38 int zuo=a[l].h,you=a[r].h;
39 int ans=0;
40 if (a[l].block*mid>=r) return find1(l,r,d-a[zuo].tag);
41 ans+=find1(l,a[l].block*mid,d-a[zuo].tag);
42 for (int i=a[l].block+1;i<=a[r].block-1;i++)
43 ans+=find2((i-1)*mid+1,i*mid,d-a[(i-1)*mid+1].tag);
44 ans+=find1((a[r].block-1)*mid+1,r,d-a[you].tag);
45 return ans;
46 }
47
48 int main(){
49 freopen("magic.txt","r",stdin);
50 freopen("me.txt","w",stdout);
51 char ch[1];
52 scanf("%d%d",&n,&q);
53 mid=(int)sqrt(n)+1;
54 for (int i=1;i<=n;i++) scanf("%d",&a[i].num),c[i]=a[i].num;
55 for (int i=1;i<=n;i++)if (tot*mid>=i) a[i].block=tot,a[i].h=a[i-1].h;else a[i].block=++tot,a[i].h=i;
56 for (int i=1;i<=tot;i++)
57 sort(c+(i-1)*mid+1,c+i*mid+1);
58 for (int j=0;j<q;j++){
59 scanf("%s%d%d%d",&ch,&l,&r,&w);
60 switch(ch[0]){
61 case ‘M‘:add(l,r,w);break;
62 case ‘A‘:printf("%d\n",query(l,r,w)); break;
63 }
64 }
65 }