RT,全WA qwq
#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cmath>
using namespace std;
const int maxn = 500005;
int B=pow(maxn,2.0/3);
struct question {
int l,r,t,id;
bool operator < (const question &b) const {
if(l/B==b.l/B) {
if(r/B==b.r/B) return t<b.t;
else return r/B<b.r/B;
} else return l/B<b.l/B;
}
}q[maxn];
int l=1,r,b[maxn],a[maxn],n,m,Time,t,k;
struct m{
int p,x,y;
}md[maxn];
int tans,ans[maxn],cnt[maxn];
void update(int x,int f) {
cnt[x]+=f;
if(cnt[x]==0&&f==-1) tans--;
if(cnt[x]==1&&f==1) tans++;
}
void updateTime(int t,int f) {
if(f==1) {
if(l<=md[t].p&&md[t].p<=r) update(md[t].x,-1),update(md[t].y,1);
a[md[t].p]=md[t].y;
} else {
if(l<=md[t].p&&md[t].p<=r) update(md[t].y,-1),update(md[t].x,1);
a[md[t].p]=md[t].x;
}
}
int main() {
clock_t c1=clock();
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
//=========================================
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
b[i]=a[i];
}
for(int i=1;i<=m;i++) {
char opt[20];
int l,r;
scanf("%s%d%d",opt,&l,&r);
if(opt[0]=='Q') {
k++;
q[k]={l,r,Time,k};
} else {
md[++Time]={l,b[l],r};
b[l]=r;
}
}
// B=ceil(exp((log(n)+log(k))/3));
sort(q+1,q+1+k);
// printf("K:%d\n",k);
l=1,r=0,t=0;
for(int i=1;i<=k;i++) {
while(t<q[i].t) updateTime(++t,1);
while(t>q[i].t) updateTime(t--,-1);
while(l<q[i].l) update(a[l++],-1);
while(l>q[i].l) update(a[--l],1);
while(r<q[i].r) update(a[++r],1);
while(r>q[i].r) update(a[r--],-1);
ans[q[i].id]=tans;
}
for(int i=1;i<=k;i++) {
printf("%d\n",ans[i]);
}
//=========================================
cerr<<"Tmie Used:"<<clock()-c1<<"ms"<<endl;
return 0;
}