///HEADERS
#include <bits/stdc++.h>
///PREPROCESSORS
#define ll long long int
#define ull unsigned ll
#define vii vector<int>
#define vll vector<ll>
#define pb push_back
#define LIM 100000
#define MOD 1000000007
#define MAX 10000000
#define pi acos(-1)
#define segVar int lft = node << 1 , rgt = (node << 1) + 1 , md = (st+ed) >> 1;
#define pii pair<int,int>
#define mpr make_pair
#define EPS 1e-9
#define sqr(x) ((x)*(x))
#define gamma 0.5772156649
#define harm(x) log(x) + gamma + 1.0/(2*x) - 1.0/(12*sqr(x))
#define joshephus(n,k) j(int n, int k) {ll res = 1; for(ll i=2; i<=n; i++) res = (res+k-1) % i + 1; return res;}
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
///IMPORTANT EQUATIONS
///STARS AND BARS : (n+k-1)C(k-1)
///STIRLING TWO : F(n,k) = F(n-1,k-1) + k*(n-1,k); F(n,1) = 1 , F(n,n) = 1;
///STIRLING ONE : F(n,k) = F(n-1,k-1) + (n-1)*(n-1,k); F(n,1) = (n-1)! , F(n,n) = 1;
///CATALAN NUMBER : Cat(n) = Comb(2n,n) - Comb(2n,n-1) = Comb(2n,n)/(n+1);
using namespace std;
struct info{
char cmd;
int x,y,z;
info() {x = y = z = 0;}
info(char c, int xx, int yy = 0, int zz = 0) {
cmd = c; x = xx; y = yy; z = zz;
}
};
int n,q,v, mxx,seg;
int a[LIM+10], val[2*LIM+10];
info qry[LIM + 10];
map<int, int> mp;
int BIT[400][LIM+100];
void update(int node, int pos, int val) {
while(node <= seg+1) {
int tp = pos;
while(tp <= mxx) {
BIT[node][tp] += val;
tp += (tp & -tp);
}
node += (node & -node);
}
}
int query(int node, int pos) {
int ans = 0;
while(node > 0) {
int tp = pos;
while(tp > 0) {
ans += BIT[node][tp];
tp -= (tp & -tp);
}
node -= (node & -node);
}
return ans;
}
int f(int x, int y, int z) {
int ans = 0;
while(x%seg) {
if(a[x] <= z) ans++;
x++;
}
while(y%seg != seg-1) {
if(a[x] <= z) ans++;
y--;
}
ans += query(y/seg+1, mp[z]) - (query(x/seg, mp[z]));
return ans;
}
int main() {
// freopen("i.txt", "r", stdin);
// freopen("o.txt", "w",stdout);
scanf("%d %d", &n,&q);
for(int i=0; i<n; i++) scanf("%d", &a[i]) , val[v++] = a[i] ;
for(int i=0; i<q; i++) {
char c; int x,y,z;
getchar();
scanf("%c", &c);
if(c == 'M') {
scanf("%d %d", &x,&y);
x--;
val[v++] = y;
qry[i] = info(c, x, y);
}
else {
scanf("%d %d %d", &x,&y,&z);
val[v++] = z;
x--; y--;
qry[i] = info(c,x,y,z);
}
}
sort(val, val+v);
for(int i=0; i<v; i++) if(!mp[ val[i] ]) mp[ val[i] ] = ++mxx;
seg = sqrt(n);
for(int i=0; i<n; i++) update(i/seg+1, mp[ a[i] ], 1);
for(int i=0; i<q; i++) {
char c; int x,y,z;
c = qry[i].cmd ; x = qry[i].x; y = qry[i].y; z = qry[i].z;
if(c == 'M') {
update(x/seg+1, mp[ a[x] ], -1);
a[x] = y;
update(x/seg+1, mp[ y ], 1);
}
else printf("%d\n", f(x,y,z));
}
return 0;
}
Ly8vSEVBREVSUwojaW5jbHVkZSAgICA8Yml0cy9zdGRjKysuaD4KLy8vUFJFUFJPQ0VTU09SUwojZGVmaW5lICAgICBsbCAgICAgICAgICAgICAgbG9uZyBsb25nIGludAojZGVmaW5lICAgICB1bGwgICAgICAgICAgICAgdW5zaWduZWQgbGwKI2RlZmluZSAgICAgdmlpICAgICAgICAgICAgIHZlY3RvcjxpbnQ+CiNkZWZpbmUgICAgIHZsbCAgICAgICAgICAgICB2ZWN0b3I8bGw+CiNkZWZpbmUgICAgIHBiICAgICAgICAgICAgICBwdXNoX2JhY2sKI2RlZmluZSAgICAgTElNICAgICAgICAgICAgIDEwMDAwMAojZGVmaW5lICAgICBNT0QgICAgICAgICAgICAgMTAwMDAwMDAwNwojZGVmaW5lICAgICBNQVggICAgICAgICAgICAgMTAwMDAwMDAKI2RlZmluZSAgICAgcGkgICAgICAgICAgICAgIGFjb3MoLTE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zEpOwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBpbmZvewogICAgY2hhciBjbWQ7CiAgICBpbnQgeCx5LHo7CiAgICBpbmZvKCkge3ggPSB5ID0geiA9IDA7fQogICAgaW5mbyhjaGFyIGMsIGludCB4eCwgaW50IHl5ID0gMCwgaW50IHp6ID0gMCkgewogICAgICAgIGNtZCA9IGM7IHggPSB4eDsgeSA9IHl5OyB6ID0geno7CiAgICB9Cn07CgppbnQgbixxLHYsIG14eCxzZWc7CmludCBhW0xJTSsxMF0sIHZhbFsyKkxJTSsxMF07CmluZm8gcXJ5W0xJTSArIDEwXTsKbWFwPGludCwgaW50PiBtcDsKaW50IEJJVFs0MDBdW0xJTSsxMDBdOwoKdm9pZCB1cGRhdGUoaW50IG5vZGUsIGludCBwb3MsIGludCB2YWwpIHsKICAgIHdoaWxlKG5vZGUgPD0gc2VnKzEpIHsKICAgICAgICBpbnQgdHAgPSBwb3M7CiAgICAgICAgd2hpbGUodHAgPD0gbXh4KSB7CiAgICAgICAgICAgIEJJVFtub2RlXVt0cF0gKz0gdmFsOwogICAgICAgICAgICB0cCArPSAodHAgJiAtdHApOwogICAgICAgIH0KICAgICAgICBub2RlICs9IChub2RlICYgLW5vZGUpOwogICAgfQp9CmludCBxdWVyeShpbnQgbm9kZSwgaW50IHBvcykgewogICAgaW50IGFucyA9IDA7CiAgICB3aGlsZShub2RlID4gMCkgewogICAgICAgIGludCB0cCA9IHBvczsKICAgICAgICB3aGlsZSh0cCA+IDApIHsKICAgICAgICAgICAgYW5zICs9IEJJVFtub2RlXVt0cF07CiAgICAgICAgICAgIHRwIC09ICh0cCAmIC10cCk7CiAgICAgICAgfQogICAgICAgIG5vZGUgLT0gKG5vZGUgJiAtbm9kZSk7CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CgppbnQgZihpbnQgeCwgaW50IHksIGludCB6KSB7CiAgICBpbnQgYW5zID0gMDsKICAgIHdoaWxlKHglc2VnKSB7CiAgICAgICAgaWYoYVt4XSA8PSB6KSBhbnMrKzsKICAgICAgICB4Kys7CiAgICB9CiAgICB3aGlsZSh5JXNlZyAhPSBzZWctMSkgewogICAgICAgIGlmKGFbeF0gPD0geikgYW5zKys7CiAgICAgICAgeS0tOwogICAgfQogICAgYW5zICs9IHF1ZXJ5KHkvc2VnKzEsIG1wW3pdKSAtIChxdWVyeSh4L3NlZywgbXBbel0pKTsKICAgIHJldHVybiBhbnM7Cn0KCmludCBtYWluKCkgewoKLy8gICAgZnJlb3BlbigiaS50eHQiLCAiciIsIHN0ZGluKTsKLy8gICAgZnJlb3Blbigiby50eHQiLCAidyIsc3Rkb3V0KTsKCiAgICBzY2FuZigiJWQgJWQiLCAmbiwmcSk7CiAgICBmb3IoaW50IGk9MDsgaTxuOyBpKyspIHNjYW5mKCIlZCIsICZhW2ldKSAsIHZhbFt2KytdID0gYVtpXSA7CiAgICBmb3IoaW50IGk9MDsgaTxxOyBpKyspIHsKICAgICAgICBjaGFyIGM7IGludCB4LHksejsKICAgICAgICBnZXRjaGFyKCk7CiAgICAgICAgc2NhbmYoIiVjIiwgJmMpOwogICAgICAgIGlmKGMgPT0gJ00nKSB7CiAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsICZ4LCZ5KTsKICAgICAgICAgICAgeC0tOwogICAgICAgICAgICB2YWxbdisrXSA9IHk7CiAgICAgICAgICAgIHFyeVtpXSA9IGluZm8oYywgeCwgeSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBzY2FuZigiJWQgJWQgJWQiLCAmeCwmeSwmeik7CiAgICAgICAgICAgIHZhbFt2KytdID0gejsKICAgICAgICAgICAgeC0tOyB5LS07CiAgICAgICAgICAgIHFyeVtpXSA9IGluZm8oYyx4LHkseik7CiAgICAgICAgfQogICAgfQogICAgc29ydCh2YWwsIHZhbCt2KTsKICAgIGZvcihpbnQgaT0wOyBpPHY7IGkrKykgaWYoIW1wWyB2YWxbaV0gXSkgbXBbIHZhbFtpXSBdID0gKytteHg7CgogICAgc2VnID0gc3FydChuKTsKICAgIGZvcihpbnQgaT0wOyBpPG47IGkrKykgdXBkYXRlKGkvc2VnKzEsIG1wWyBhW2ldIF0sIDEpOwoKICAgIGZvcihpbnQgaT0wOyBpPHE7IGkrKykgewogICAgICAgIGNoYXIgYzsgaW50IHgseSx6OwogICAgICAgIGMgPSBxcnlbaV0uY21kIDsgeCA9IHFyeVtpXS54OyB5ID0gcXJ5W2ldLnk7IHogPSBxcnlbaV0uejsKICAgICAgICBpZihjID09ICdNJykgewogICAgICAgICAgICB1cGRhdGUoeC9zZWcrMSwgbXBbIGFbeF0gXSwgLTEpOwogICAgICAgICAgICBhW3hdID0geTsKICAgICAgICAgICAgdXBkYXRlKHgvc2VnKzEsIG1wWyB5IF0sIDEpOwogICAgICAgIH0KICAgICAgICBlbHNlIHByaW50ZigiJWRcbiIsIGYoeCx5LHopKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=