rt,求大佬帮忙/kel
//#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
//#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
const int maxn=133333;
struct query {
int l,r,id,bel,num;
}q[maxn];
struct modify {
int x,val,pre;
}c[maxn];
bool cmp(query x,query y) {
if(x.bel!=y.bel) {
return x.bel<y.bel;
}
if(x.r!=y.r)
return x.r<y.r;
return x.num<y.num;
}
int n,ans[maxn],m,a[maxn],cur,b[maxn],num[1000010];
void add(int x) {
num[x]++;
if(num[x]==1) {
cur++;
}
}
void del(int x){
num[x]--;
if(num[x]==0) {
cur--;
}
}
signed main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();m=read();
int block=sqrt(n),mnum=0,cntq=0,cntm=0;
fill(ans,ans+1+m,-1);
for(int i=1;i<=n;i++) {
a[i]=read();
b[i]=a[i];
}
for(int i=1;i<=m;i++) {
char s;
cin>>s;
if(s=='Q') {
q[++cntq].l=read();
q[cntq].r=read();
q[cntq].bel=(q[i].l-1)/block+1;
q[cntq].id=i;
q[cntq].num=mnum;
}
else {
c[++cntm].x=read();
c[cntm].val=read();
c[cntm].pre=b[c[cntm].x];
b[c[cntm].x]=c[cntm].val;
mnum++;
}
}
int l=1,r=0,ch=0;
sort(q+1,q+cntq+1,cmp);
for(int i=1;i<=cntq;i++) {
while(l<q[i].l) del(a[l++]);
while(l>q[i].l) add(a[--l]);
while(r<q[i].r) add(a[++r]);
while(r>q[i].r) del(a[r--]);
while(ch>q[i].num) {
if(c[ch].x>=l&&c[ch].x<=r) {
del(c[ch].val);
add(c[ch].pre);
}
a[c[ch].x]=c[ch].pre;
ch--;
}
while(ch<q[i].num) {
ch++;
a[c[ch].x]=c[ch].val;
if(c[ch].x>=l&&c[ch].x<=r) {
del(c[ch].pre);
add(c[ch].val);
}
}
ans[q[i].id]=cur;
}
for(int i=1;i<=m;i++) {
if(ans[i]!=-1) {
printf("%lld\n",ans[i]);
}
}
//fclose(stdin);
//fclose(stdout);
return 0;
}