#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>
const int N = 50000;
const int MAX = 1000000;
struct Query;
struct Change;
struct Query {
int l, r;
Change *x;
int *ans;
} querys[N + 1], *queryEnd;
struct Change {
int pos, newVal, oldVal;
} changes[N + 1], *changeEnd;
int n, m;
int block[N + 1], last[N + 1];
int res, ans[N + 1];
bool affected[N + 1];
int buc[MAX + 1], a[N + 1];
int l, r;
Change *now;
int blockSize;
inline bool comp(const Query &x, const Query &y) {
return block[x.l] < block[y.l] ||
block[x.l] == block[y.l] && block[x.r] < block[y.r] ||
block[x.l] == block[y.l] && block[x.r] == block[y.r] && x.x < y.x;
}
inline void update(int pos) {
if (affected[pos]) {
if (!--buc[a[pos]]) res--;
} else {
if (!buc[a[pos]]++) res++;
}
affected[pos] ^= 1;
}
inline void modify(int pos, int val) {
if (affected[pos]) {
update(pos);
a[pos] = val;
update(pos);
} else a[pos] = val;
}
int main() {
queryEnd = querys;
changeEnd = changes;
scanf("%d %d", &n, &m);
blockSize = 1500;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
block[i] = i / blockSize;
last[i] = a[i];
}
for (int i = 1; i <= m; i++) {
char s[10];
int x, y;
scanf("%s %d %d", s, &x, &y);
if (s[0] == 'Q') {
x++;
queryEnd++;
queryEnd->l = x;
queryEnd->r = y;
queryEnd->x = changeEnd;
queryEnd->ans = &ans[queryEnd - querys];
} else {
x++;
changeEnd++;
changeEnd->pos = x;
changeEnd->newVal = y;
changeEnd->oldVal = last[x];
last[x] = y;
}
}
std::sort(querys + 1, queryEnd + 1, comp);
l = 1;
r = 0;
now = changes;
for (Query *v = querys + 1; v != queryEnd + 1; v++) {
if (now == v->x) {}
else if (now < v->x) {
for (Change *p = now + 1; p != v->x + 1; p++) modify(p->pos, p->newVal);
} else {
for (Change *p = now; p != v->x + 1 - 1; p--) modify(p->pos, p->oldVal);
}
if (l == v->l) {}
if (l < v->l) for (int i = l; i <= v->l - 1; i++) update(i);
else for (int i = v->l; i <= l - 1; i++) update(i);
if (r == v->r) {}
if (r < v->r) for (int i = r + 1; i <= v->r; i++) update(i);
else for (int i = v->r + 1; i <= r; i++) update(i);
l = v->l;
r = v->r;
now = v->x;
*v->ans = res;
}
for (int i = 1; i <= queryEnd - querys; i++) printf("%d\n", ans[i]);
return 0;
}