#include <cstdio>
#include <iostream>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forv(i, v) for(int i = 0; i < int(v.size()); i++)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
inline int ni() { int a; scanf("%d", &a); return a; }
const int max_n = 100000;
struct treap {
int l, r, key, value, size, count;
treap() { }
treap(int key, int value) { this->l = this->r = -1, this->key = key, this->value = value, this->size = 1, this->count = 1; }
};
treap treaps[60 * max_n];
int arr[max_n], st[4 * max_n];
char buffer[8];
int treaps_sz = 0;
inline int rand_int() {
return rand() << 15 + rand();
}
inline int treap_size(int t) {
if(t == -1) return 0;
return treaps[t].size;
}
inline int treap_create(int value) {
treaps[treaps_sz] = treap(rand_int(), value);
return treaps_sz++;
}
inline void treap_recalc(int t) {
treaps[t].size = treap_size(treaps[t].l) + treap_size(treaps[t].r) + treaps[t].count;
}
int treap_merge(int l, int r) {
if(l == -1) return r;
if(r == -1) return l;
if(treaps[l].key > treaps[r].key) {
treaps[l].r = treap_merge(treaps[l].r, r);
treap_recalc(l);
return l;
} else {
treaps[r].l = treap_merge(l, treaps[r].l);
treap_recalc(r);
return r;
}
}
pair < int, int > treap_split(int t, int value) {
if(t == -1) return mp(-1, -1);
if(treaps[t].value >= value) {
pair < int, int > s = treap_split(treaps[t].l, value);
treaps[t].l = s.second;
s.second = t;
treap_recalc(t);
return s;
} else {
pair < int, int > s = treap_split(treaps[t].r, value);
treaps[t].r = s.first;
s.first = t;
treap_recalc(t);
return s;
}
}
void treap_add(int & t, int value) {
pair < int, int > fs = treap_split(t, value);
pair < int, int > ss = treap_split(fs.second, value + 1);
if(ss.first == -1) {
ss.first = treap_create(value);
} else {
treaps[ss.first].count++;
treap_recalc(ss.first);
}
t = treap_merge(fs.first, treap_merge(ss.first, ss.second));
}
void treap_remove(int & t, int value) {
pair < int, int > fs = treap_split(t, value);
pair < int, int > ss = treap_split(fs.second, value + 1);
if(ss.first != -1) {
treaps[ss.first].count--;
if(treaps[ss.first].count == 0) ss.first = -1;
}
t = treap_merge(fs.first, treap_merge(ss.first, ss.second));
}
inline int treap_how_much(int & t, int a, int b) {
pair < int, int > fs = treap_split(t, a);
pair < int, int > ss = treap_split(fs.second, b + 1);
int res = treap_size(ss.first);
t = treap_merge(fs.first, treap_merge(ss.first, ss.second));
return res;
}
inline int left(int v) { return (v << 1); }
inline int right(int v) { return (v << 1) + 1; }
void st_build(int v, int l, int r) {
st[v] = -1;
if(l != r) {
int m = (l + r) >> 1;
st_build(left(v), l, m);
st_build(right(v), m + 1, r);
}
for(int i = l; i <= r; i++) treap_add(st[v], arr[i]);
}
void st_remove_and_add(int v, int l, int r, int ind, int old_val, int new_val) {
if(l != r) {
int m = (l +r) >> 1;
if(ind <= m) st_remove_and_add(left(v), l, m, ind, old_val, new_val);
else st_remove_and_add(right(v), m + 1, r, ind, old_val, new_val);
}
treap_remove(st[v], old_val);
treap_add(st[v], new_val);
}
int st_query(int v, int l, int r, int tl, int tr, int a, int b) {
if(l == tl && r == tr) {
return treap_how_much(st[v], a, b);
} else {
int m = (l + r) >> 1, res = 0;
if(tl <= m) res += st_query(left(v), l, m, tl, min(tr, m), a, b);
if(tr > m) res += st_query(right(v), m + 1, r, max(m + 1, tl), tr, a, b);
return res;
}
}
int main() {
//freopen("h8.in", "r", stdin);
//freopen("h8.out", "w", stdout);
int n = ni(), m = ni();
forn(i, n) arr[i] = ni();
st_build(1, 0, n - 1);
forn(i, m) {
scanf("%s", buffer);
if(buffer[0] == 'G') {
int l = ni() - 1, r = ni() - 1, a = ni(), b = ni();
printf("%d\n", st_query(1, 0, n - 1, l, r, a, b));
} else {
int ind = ni() - 1, value = ni();
st_remove_and_add(1, 0, n - 1, ind, arr[ind], value);
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5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