# bzoj 3343: 教主的魔法

 1 #include<bits/stdc++.h>
2 #define N 1000005
3 #define LL long long
4 #define inf 0x3f3f3f3f
5 using namespace std;
6 inline int ra()
7 {
8     int x=0,f=1; char ch=getchar();
9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
11     return x*f;
12 }
13 int block,m,n,Q;
15 int find(int i, int w)
16 {
17     int l=(i-1)*block+1,r=min(i*block,n),orz=r;
18 //    for (int j=l; j<=r; j++) printf("%d  ",sot[j]+add[i]);
20     while (l<r)
21     {
22         int mid=l+r>>1;
24         else l=mid+1;
25     }
27     else return orz-l+1;
28 }
29 int ask(int l, int r, int w)
30 {
31     int ans=0;
32     if (pos[l]==pos[r]){
33         for (int i=l; i<=r; i++)
35     }
36     else{
37         for (int i=l; i<=pos[l]*block; i++) if (add[pos[l]]+a[i]>=w) ans++;
38         for (int i=(pos[r]-1)*block+1; i<=r; i++) if (add[pos[r]]+a[i]>=w) ans++;
39     //    cout<<ans;
40         for (int i=pos[l]+1; i<pos[r]; i++)
41             ans+=find(i,w);
42     }
43     return ans;
44 }
45 void change(int l, int r, int w)
46 {
47     if (pos[l]==pos[r]){
48         for (int i=l; i<=r; i++) a[i]+=w;
49         for (int i=(pos[l]-1)*block+1; i<=pos[l]*block; i++)
50             sot[i]=a[i];
51         sort(sot+(pos[l]-1)*block+1,sot+pos[l]*block+1);
52     }
53     else {
54         for (int i=l; i<=pos[l]*block; i++) a[i]+=w;
55         for (int i=(pos[l]-1)*block+1; i<=pos[l]*block; i++) sot[i]=a[i];
56         sort(sot+(pos[l]-1)*block+1,sot+pos[l]*block+1);
57         for (int i=(pos[r]-1)*block+1; i<=r; i++) a[i]+=w;
58         for (int i=(pos[r]-1)*block+1; i<=pos[r]*block; i++) sot[i]=a[i];
59         sort(sot+(pos[r]-1)*block+1,sot+pos[r]*block+1);
60         for (int i=pos[l]+1; i<pos[r]; i++) add[i]+=w;
61     }
62 }
63 int main()
64 {
65     n=ra(); Q=ra();
66     block=sqrt(n); m=n/block+(n%block!=0);
67     for (int i=1; i<=n; i++)
68         a[i]=ra(),pos[i]=(i-1)/block+1,sot[i]=a[i];
69     for (int i=1; i<=m; i++)
70     {
71         int l=(i-1)*block+1,r=min(n,i*block);
72         sort(sot+l,sot+r+1);
73     }
74     while (Q--)
75     {
76         char s[3]; scanf("%s",s); int x=ra(),y=ra(),w=ra();
77         if (s[0]=='M') change(x,y,w);
82 }