JACKLOVEONE @ 2018-04-03 17:23:07
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n, laz[maxn], blo, l[maxn], r[maxn];
int a[maxn], q, bl[maxn];
vector<int>v[5000];
void calc(int x) {
v[bl[x]].clear();
for (int i = l[bl[x]]; i <= r[bl[x]]; ++i) {
v[bl[x]].push_back(a[i]);
} sort(v[bl[x]].begin(), v[bl[x]].end());
}
void add(int L, int R, int C) {
for (int i = L; i <= min(R, r[bl[L]]); ++i) a[i] += C; calc(L);
if(bl[L] != bl[R]) {
for (int i = l[bl[R]]; i <= R; ++i) a[i] += C;
calc(R);
}
for (int i = bl[L] + 1; i <= bl[R] - 1; ++i) laz[i] += C;
}
int query(int L, int R, int C) {
int res = 0;
for (int i = L; i <= min(R, r[bl[L]]); ++i) if (a[i] + laz[bl[L]] >= C) res++;
if(bl[L] != bl[R])
for (int i = l[bl[R]]; i <= R; ++i) if(a[i] + laz[bl[R]] >= C) res++;
for (int i = bl[L] + 1; i <= bl[R] - 1; ++i) {
int x = C - laz[i];
res += r[i] - (lower_bound(v[i].begin(), v[i].end(), x) - v[i].begin()) + 1;
}
return res;
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}blo = 1000;
for (int i = 1; i <= n; ++i) bl[i] = (i - 1) / blo + 1;
for (int i = 1; i <= n; ++i) if(!l[bl[i]]) l[bl[i]] = i;
for (int i = n; i >= 1; --i) if(!r[bl[i]]) r[bl[i]] = i;
for (int i = 1; i <= n; ++i) v[bl[i]].push_back(a[i]);
for (int i = 1; i <= bl[n]; ++i) {
sort(v[i].begin(),v[i].end());
}
for (int i = 1; i <= q; ++i) {
char c[2];
int A, B, C;
scanf("%s%d%d%d", c, &A, &B, &C);
if(c[0] == 'M') add(A, B, C);
else printf("%d\n", query(A, B, C));
}
return 0;
}