#include<algorithm>#include<cmath>#include<iostream>#define int long long#define endl '\n'usingnamespacestd;intqsize;structquery{intid,t,l,r;inlinebooloperator<(queryb){if(l/qsize!=b.l/qsize){returnl/qsize>b.l/qsize;}elseif(r/qsize!=b.r/qsize){returnr/qsize>b.r/qsize;}else{returnt>b.t;}}}q[150009];structoperation{intp,x;}r[150009];charop;intn,m,x,y,cur,qcnt,rcnt,mp[1500009],a[150009],ans[150009];inlinevoidadd(intx){if(!mp[x]){cur+=1;}mp[x]+=1;}inlinevoiddel(intx){mp[x]-=1;if(!mp[x]){cur-=1;}}inlinevoidprocess(){sort(q+1,q+qcnt+1);intL=1,R=0,last=0;for(inti=1;i<=qcnt;i++){while(R<q[i].r){add(a[++R]);}while(R>q[i].r){del(a[R--]);}while(L>q[i].l){add(a[--L]);}while(L<q[i].l){del(a[L++]);}while(last<q[i].t){last+=1;if(r[last].p>=L&&r[last].p<=R){add(r[last].x);del(a[r[last].p]);}swap(a[r[last].p],r[last].x);}while(last>q[i].t){if(r[last].p>=L&&r[last].p<=R){add(r[last].x);del(a[r[last].p]);}swap(a[r[last].p],r[last].x);last-=1;}ans[q[i].id]=cur;}}signedmain(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cin>>n>>m;qsize=pow(n,2.0/3.0);for(inti=1;i<=n;i++){cin>>a[i];}for(inti=1;i<=m;i++){cin>>op>>x>>y;if(op=='Q'){q[++qcnt]={qcnt,rcnt,x,y};}elseif(op=='R'){r[++rcnt]={x,y};}}process();for(inti=1;i<=qcnt;i++){cout<<ans[i]<<endl;}}