#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int v[100005];
const int BUCKET_SIZE = 320;
int S[BUCKET_SIZE][BUCKET_SIZE];
vector<int> M[BUCKET_SIZE];
int n;
void build(){
for(int i = 0; i < n ; i += BUCKET_SIZE){
int inicio = i;
int fin = min(i + BUCKET_SIZE - 1, n - 1);
vector<int> aux;
for(int j = inicio; j <= fin; j++){
aux.push_back(v[j]);
}
sort(aux.begin(), aux.end());
for(int j = 0, pos = 0; j < aux.size(); pos++){
int valor = aux[j];
int e = j;
M[i/BUCKET_SIZE].push_back(valor);
while(aux[e] == valor && e < aux.size()){
e++;
}
S[i/BUCKET_SIZE][pos] += e - j;
if(pos) S[i/BUCKET_SIZE][pos] += S[i/BUCKET_SIZE][pos-1];
j = e;
}
}
}
void update(int pos, int val){
v[pos] = val;
int bucket = pos / BUCKET_SIZE;
int inicio = BUCKET_SIZE * bucket;
int fin = min(inicio + BUCKET_SIZE - 1, n - 1);
vector<int> aux;
for(int j = inicio; j <= fin; j++){
aux.push_back(v[j]);
}
sort(aux.begin(), aux.end());
M[bucket].clear();
for(int j = 0, pos = 0; j < aux.size(); pos++){
int valor = aux[j];
int e = j;
M[bucket].push_back(valor);
while(aux[e] == valor && e < aux.size()){
e++;
}
S[bucket][pos] = e - j;
if(pos) S[bucket][pos] += S[bucket][pos-1];
j = e;
}
}
int query(int l, int r, int x){
int bucket = l / BUCKET_SIZE;
int ans = 0;
for(int i = bucket; ; i++){
int inicio = i * BUCKET_SIZE;
int fin = min(i * BUCKET_SIZE - 1, n - 1);
if(inicio > r) break;
int p = lower_bound( M[i].begin(), M[i].end(), x) - M[i].begin();
if(p == M[i].size()) p--;
if(M[i][p] > x) p--;
if(inicio >= l && fin <= r){
ans += S[i][p];
continue;
}
if(inicio < l){
for(int j = l; j <= fin; j++){
ans += (v[j] <= x);
}
}
if(fin > r){
for(int j = inicio; j <= r; j++){
ans += (v[j] <= x);
}
}
}
return ans;
}
int main()
{
int q; scanf("%d %d", &n, &q);
for(int i = 0; i < n; i++){
scanf("%d", &v[i]);
}
build();
for(int i = 0 ; i < q; i++){
char command; scanf(" %c", &command);
if(command == 'Q'){
int l, r, x; scanf("%d %d %d", &l, &r, &x);
l--, r--;
printf("%d\n", query(l, r, x) );
}else{
int pos, x; scanf("%d %d", &pos, &x);
pos--;
update(pos, x);
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgoKI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCB2WzEwMDAwNV07CmNvbnN0IGludCBCVUNLRVRfU0laRSA9IDMyMDsKCmludCBTW0JVQ0tFVF9TSVpFXVtCVUNLRVRfU0laRV07Cgp2ZWN0b3I8aW50PiBNW0JVQ0tFVF9TSVpFXTsKCmludCBuOwoKdm9pZCBidWlsZCgpewoKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuIDsgaSArPSBCVUNLRVRfU0laRSl7CiAgICAgICAgaW50IGluaWNpbyA9IGk7CiAgICAgICAgaW50IGZpbiA9IG1pbihpICsgQlVDS0VUX1NJWkUgLSAxLCBuIC0gMSk7CgogICAgICAgIHZlY3RvcjxpbnQ+IGF1eDsKICAgICAgICBmb3IoaW50IGogPSBpbmljaW87IGogPD0gZmluOyBqKyspewogICAgICAgICAgICBhdXgucHVzaF9iYWNrKHZbal0pOwogICAgICAgIH0KCiAgICAgICAgc29ydChhdXguYmVnaW4oKSwgYXV4LmVuZCgpKTsKCiAgICAgICAgZm9yKGludCBqID0gMCwgcG9zID0gMDsgaiA8IGF1eC5zaXplKCk7IHBvcysrKXsKICAgICAgICAgICAgaW50IHZhbG9yID0gYXV4W2pdOwogICAgICAgICAgICBpbnQgZSA9IGo7CgogICAgICAgICAgICBNW2kvQlVDS0VUX1NJWkVdLnB1c2hfYmFjayh2YWxvcik7CgogICAgICAgICAgICB3aGlsZShhdXhbZV0gPT0gdmFsb3IgJiYgZSA8IGF1eC5zaXplKCkpewogICAgICAgICAgICAgICAgZSsrOwogICAgICAgICAgICB9CgogICAgICAgICAgICBTW2kvQlVDS0VUX1NJWkVdW3Bvc10gKz0gZSAtIGo7CiAgICAgICAgICAgIGlmKHBvcykgU1tpL0JVQ0tFVF9TSVpFXVtwb3NdICs9IFNbaS9CVUNLRVRfU0laRV1bcG9zLTFdOwoKICAgICAgICAgICAgaiAgPSBlOwoKICAgICAgICB9CgoKICAgIH0KfQoKdm9pZCB1cGRhdGUoaW50IHBvcywgaW50IHZhbCl7CgogICAgdltwb3NdID0gdmFsOwogICAgaW50IGJ1Y2tldCA9IHBvcyAvIEJVQ0tFVF9TSVpFOwoKICAgIGludCBpbmljaW8gPSBCVUNLRVRfU0laRSAqIGJ1Y2tldDsKICAgIGludCBmaW4gPSBtaW4oaW5pY2lvICsgQlVDS0VUX1NJWkUgLSAxLCBuIC0gMSk7CgogICAgdmVjdG9yPGludD4gYXV4OwogICAgZm9yKGludCBqID0gaW5pY2lvOyBqIDw9IGZpbjsgaisrKXsKICAgICAgICBhdXgucHVzaF9iYWNrKHZbal0pOwogICAgfQoKICAgIHNvcnQoYXV4LmJlZ2luKCksIGF1eC5lbmQoKSk7CgogICAgTVtidWNrZXRdLmNsZWFyKCk7CiAgICBmb3IoaW50IGogPSAwLCBwb3MgPSAwOyBqIDwgYXV4LnNpemUoKTsgcG9zKyspewogICAgICAgIGludCB2YWxvciA9IGF1eFtqXTsKICAgICAgICBpbnQgZSA9IGo7CgogICAgICAgIE1bYnVja2V0XS5wdXNoX2JhY2sodmFsb3IpOwoKICAgICAgICB3aGlsZShhdXhbZV0gPT0gdmFsb3IgJiYgZSA8IGF1eC5zaXplKCkpewogICAgICAgICAgICBlKys7CiAgICAgICAgfQoKICAgICAgICBTW2J1Y2tldF1bcG9zXSA9IGUgLSBqOwogICAgICAgIGlmKHBvcykgU1tidWNrZXRdW3Bvc10gKz0gU1tidWNrZXRdW3Bvcy0xXTsKICAgICAgICBqICA9IGU7CgogICAgfQoKfQoKaW50IHF1ZXJ5KGludCBsLCBpbnQgciwgaW50IHgpewoKICAgIGludCBidWNrZXQgPSBsIC8gQlVDS0VUX1NJWkU7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvcihpbnQgaSA9IGJ1Y2tldDsgOyBpKyspewoKICAgICAgICBpbnQgaW5pY2lvID0gaSAgKiBCVUNLRVRfU0laRTsKICAgICAgICBpbnQgZmluID0gbWluKGkgKiBCVUNLRVRfU0laRSAtIDEsIG4gLSAxKTsKICAgICAgICBpZihpbmljaW8gPiByKSBicmVhazsKICAgICAgICAKICAgICAgICBpbnQgcCA9IGxvd2VyX2JvdW5kKCBNW2ldLmJlZ2luKCksIE1baV0uZW5kKCksIHgpIC0gTVtpXS5iZWdpbigpOwoKICAgICAgICBpZihwID09IE1baV0uc2l6ZSgpKSBwLS07CgogICAgICAgIGlmKE1baV1bcF0gPiB4KSBwLS07CgogICAgICAgIGlmKGluaWNpbyA+PSBsICYmIGZpbiA8PSByKXsKICAgICAgICAgICAgYW5zICs9IFNbaV1bcF07CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZihpbmljaW8gPCBsKXsKCiAgICAgICAgICAgIGZvcihpbnQgaiA9IGw7IGogPD0gZmluOyBqKyspewogICAgICAgICAgICAgICAgYW5zICs9ICh2W2pdIDw9IHgpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpZihmaW4gPiByKXsKICAgICAgICAgICAgZm9yKGludCBqID0gaW5pY2lvOyBqIDw9IHI7IGorKyl7CiAgICAgICAgICAgICAgICBhbnMgKz0gKHZbal0gPD0geCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYW5zOwoKfQppbnQgbWFpbigpCnsKICAgIGludCBxOyBzY2FuZigiJWQgJWQiLCAmbiwgJnEpOwoKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIHNjYW5mKCIlZCIsICZ2W2ldKTsKICAgIH0KCiAgICBidWlsZCgpOwoKICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgcTsgaSsrKXsKICAgICAgICBjaGFyIGNvbW1hbmQ7IHNjYW5mKCIgJWMiLCAmY29tbWFuZCk7CgogICAgICAgIGlmKGNvbW1hbmQgPT0gJ1EnKXsKICAgICAgICAgICAgaW50IGwsIHIsIHg7IHNjYW5mKCIlZCAlZCAlZCIsICZsLCAmciwgJngpOwogICAgICAgICAgICBsLS0sIHItLTsKCiAgICAgICAgICAgIHByaW50ZigiJWRcbiIsIHF1ZXJ5KGwsIHIsIHgpICk7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIGludCBwb3MsIHg7IHNjYW5mKCIlZCAlZCIsICZwb3MsICZ4KTsKICAgICAgICAgICAgcG9zLS07CgogICAgICAgICAgICB1cGRhdGUocG9zLCB4KTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQo=