有修改的都挂了。
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#define N 3333333
#define ll long long
#define _it set<node>::iterator
#define frac pair<ll,ll>
using namespace std;
inline long long read(){
ll f=1,s=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
return s*f;
}
inline void write(ll i){
ll p=0,buf[1001];
if(!i) p++;
else while(i){
buf[p++] = i % 10;
i /= 10;
}
for(int j=p-1;j>=0;j--) putchar('0'+buf[j]);
}
char c;
ll n,m,block;
ll cntq,cntc;
ll num[N],s[N],sum,res,f[N];
struct node{
ll l,r,id,bf;
}q[N];
struct cg{
ll data,id;
}C[N];
ll ans[N];
inline void add(ll x){
num[x]++;
if(num[x]==1) sum++;
}
inline void del(ll x){
num[x]--;
if(!num[x]) sum--;
}
inline bool cmp(node x,node y){
return x.l/block==y.l/block?(x.r/block==y.r/block?x.bf<y.bf:x.r<y.r):x.l<y.l;
}
/*
bool cmp(const node&a,const node&b){
return (a.l/block)^(b.l/block)?(a.l/block)<(b.l/block):(a.l/block)&1?a.r<b.r:a.r>b.r;
}
*/
ll gcd(ll x,ll y){
if(!y) return x;
return gcd(y,x%y);
}
void updata(ll l,ll r,ll x){
ll id=C[x].id,data=C[x].data;
if(id>=l&&id<=r){
del(s[id]);
add(data);
}
swap(s[id],data);
}
int main(){
n=read();m=read();
for(int i=1;i<=n;i++) s[i]=read();
block=pow(n,0.666);
for(int i=1;i<=m;i++){
c=getchar();
while(c!='Q'&&c!='R') c=getchar();
if(c=='Q'){
cntq++;
q[cntq].l=read();q[cntq].r=read();
q[cntq].id=cntq;
q[cntq].bf=cntc;//时间戳
}else{
cntc++;
C[cntc].id=read();C[cntc].data=read();
}
}
sort(q+1,q+cntq+1,cmp);
//cout<<cntq<<" "<<cntc<<"\n";
ll l=1,r=0,t=0;
for(int i=1;i<=cntq;i++){
while(r<q[i].r) add(s[++r]);//,cout<<i<<" "<<l<<" "<<r<<" "<<sum<<"\n";
while(r>q[i].r) del(s[r--]);//,cout<<i<<" "<<l<<" "<<r<<" "<<sum<<"\n";
while(l<q[i].l) del(s[l++]);//,cout<<i<<" "<<l<<" "<<r<<" "<<sum<<"\n";
while(l>q[i].l) add(s[--l]);//,cout<<i<<" "<<l<<" "<<r<<" "<<sum<<"\n";
while(t<q[i].bf) updata(q[i].l,q[i].r,++t);
while(t>q[i].bf) updata(q[i].l,q[i].r,t--);
ans[q[i].id]=sum;
}
for(int i=1;i<=cntq;i++) cout<<ans[i]<<"\n";
return 0;
}