#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pii;
//#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
/*#define int __int128
inline __int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x / 10);
putchar(x%10+'0');
}
*/
int read(){
int res=0;
char c=getchar();
while(c>'9'||c<'0') c=getchar();
while(c<='9'&&c>='0') {res=(res<<1)+(res<<3)+(c^48);c=getchar();}
return res;
}
#define int long long
//const int mod=1e9+7;
struct node{
int l,r,idx;
int tim;
}b[1000005];
struct node2{
int id,y;
}c[1000005];
int n,m;
int a[1000005],s[1000005];
int N;
bool cmp(node x,node y){
if(x.l/N==y.l/N){
return x.r<y.r;
}
if(x.l/N==y.l/N)
return x.tim<y.tim;
return x.l/N<y.l/N;
}
int cnt=0;
int l,r;
//int n,m;
void add(int x){
if(s[x]==0){
cnt++;
}
s[x]++;
}
void del(int x){
if(s[x]==1)
cnt--;
s[x]--;
}
void upd(int x){
int f=c[x].id;
if(l<=f&&f<=r){
del(a[f]);
add(c[x].y);
}
swap(a[f],c[x].y);
}
int ans[1000005],cidx;
void solve(){
//cin>>n>>m;
n=read(),m=read();
for(int i=1;i<=n;i++)
a[i]=read();
//cin>>a[i];
N=pow(n,2.0/3);
int cntt=0,x,y;
char opt;
for(int i=1;i<=m;i++){
opt=getchar();
x=read();
y=read();
if(opt=='R'){
//x++;
c[++cidx].id=x;
c[cidx].y=y;
}
else{
//x++,y++;
b[++cntt].l=x,b[cntt].r=y;
b[cntt].idx=cntt;
b[cntt].tim=cidx;
}
}
sort(b+1,b+cntt+1,cmp);
l=1,r=0;
int t=0;
for(int i=1;i<=cntt;i++){
int L=b[i].l,R=b[i].r,id=b[i].idx;
while(l>L) add(a[--l]);
while(r<R) add(a[++r]);
while(l<L) del(a[l++]);
while(r>R) del(a[r--]);
while(t>b[i].tim) upd(t--);
while(t<b[i].tim) upd(++t);
ans[id]=cnt;
}
for(int i=1;i<=cntt;i++){
cout<<ans[i]<<"\n";
}
}
signed main(){
//IOS;
int t=1;
//cin>>t;
while(t--){
solve();
// cout<<"-------------------------"<<endl;
}
return 0;
}
已经和题解写的一模一样了