#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));
}
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;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jb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