#11~13 WA 了。
Code:
#include<bits/stdc++.h>
using namespace std;
#define _r return*this
#define _o &operator
namespace IO
{
const int _S=1<<21;
char b[_S],*p1=b,*p2=b,pb[_S],*pp=pb;
void fl(){fwrite(pb,1,pp-pb,stdout),pp=pb;}
struct input
{
char gc(){if(p1==p2)p2=(p1=b)+fread(b,1,_S,stdin);return p1==p2?' ':*p1++;}
input _o>>(char&num){do num=gc();while(num==' '||num=='\n'||num=='\r'||num=='\t');_r;}
template<typename T>input _o>>(T&x)
{
char c=gc();T f=1;
for(x=0;!isdigit(c);)(c=='-'?f=-1:1),c=gc();
while(isdigit(c))x=(x*10)+(c^48),c=gc();
x*=f;_r;
}
input(){}
}in;
struct output
{
void pt(char num){*pp++=num;if(pp-pb==_S)fl();}
output _o<<(char num){pt(num);_r;}
template<typename T>output _o<<(T x)
{
if(!x){pt(48);_r;}
if(x<0)pt('-'),x=-x;
int s[64],t=0;
while(x)s[++t]=x%10,x/=10;
while(t)pt(s[t--]+48);
_r;
}
output _o<<(const char*s){int num=0;while(s[num])pt(s[num++]);_r;}
output(){}
}out;
struct fe{~fe(){fl();}}fls;
int read(){int x;return in>>x,x;}
long long readll(){long long x;return in>>x,x;}
}
using IO::in;
using IO::out;
using IO::read;
using IO::readll;
using ll=long long;
using pii=pair<ll,ll>;
#define N 1000001ll
#define LEN 2610ll
struct op
{
ll l,r,t,i;
bool operator<(op B)const
{
if(l/LEN==B.l/LEN)
{
if(r/LEN==B.r/LEN)return t<B.t;
return r<B.r;
}
return l<B.l;
}
};
vector<op>Q,R;
ll ans[N];
ll a[N];
ll curL=1,curR,curT,sum;
ll f[N];
inline void add(ll v){sum+=!f[v]++;}
inline void del(ll v){sum-=!--f[v];}
inline void mov(op&q,ll r)
{
if(q.l<=R[r].l&&R[r].l<=q.r)del(a[R[r].l]),add(R[r].r);
swap(a[R[r].l],R[r].r);
}
ll n,m;
int main()
{
in>>n>>m,Q.push_back({0,0,0,0}),R.push_back({0,0,0,0});
for(int i=1;i<=n;i++)in>>a[i];
for(int i=1;i<=m;i++)
if(IO::in.gc()=='Q')Q.push_back({read(),read(),ll(R.size()-1),ll(Q.size())});
else R.push_back({read(),read(),0,0});
sort(Q.begin(),Q.end());
for(op i:Q)
{
while(i.l<curL)add(a[--curL]);
while(curR<i.r)add(a[++curR]);
while(curL<i.l)del(a[curL++]);
while(i.r<curR)del(a[curR--]);
while(curT<i.t)mov(i,++curT);
while(i.t<curT)mov(i,curT--);
ans[i.i]=sum;
}
for(size_t i=1;i<Q.size();i++)out<<ans[i]<<"\n";
}