救救孩子,卡常卡自闭了
#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
#include <cmath>
#include <cstdio>
#include <algorithm>
int a[200001], e[200001], cnt[1000001];
int tot, tott;
int ans = 0;
int l, r;
int be[200001];
int as[200001];
int i;
struct hehe{
int l, r, id, xs;
bool operator < (hehe y) const
{
if(be[l] == be[y.l]) return (be[l] & 1) ? r > y.r : r < y.r;
return l < y.l;
}
}q[200001];
struct change{
int x, lst, nxt, tim;
}c[200001];
inline void chn(int x, int la, int nx)
{
if(x <= r && x >= l)
{
cnt[la]--;
if(!cnt[la]) ans--;
if(!cnt[nx]) ans = -(~ans);
cnt[nx] = -(~cnt[nx]);
}
a[x] = nx;
}
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
signed main()
{
int n, m;
n = read(), m = read();
int bl = pow(n, 2.0 / 3);
for(i = 1; i <= n; i = -(~i))
{
a[i] = read();
e[i] = a[i];
be[i] = i / bl + 1;
}
cnt[0] = 1;
for(i = 1; i <= m; i = -(~i))
{
char ch[10];
int x, y;
scanf("%s", ch);
x = read();
y = read();
if(ch[0] == 'Q')
{
q[++tot].l = x;
q[tot].r = y;
q[tot].id = i;
q[tot].xs = tot;
}
else
{
c[++tott].x = x;
c[tott].lst = e[x];
e[x] = y;
c[tott].nxt = y;
c[tott].tim = i;
}
}
std::sort(q + 1, q + tot + 1);
l = r = 0;
int t = 0, now = 0;
c[0].tim = -1;
c[tott + 1].tim = 10000000;
ans = 1;
for(i = 1; i <= tot; i = -(~i))
{
while(c[now].tim < q[i].id) now = -(~now), chn(c[now].x, c[now].lst, c[now].nxt);
while(c[now].tim > q[i].id) chn(c[now].x, c[now].nxt, c[now].lst), now--;
while(r < q[i].r)
{
r = -(~r);
if(!cnt[a[r]]) ans = -(~ans);
cnt[a[r]] = -(~cnt[a[r]]);
}
while(r > q[i].r)
{
cnt[a[r]]--;
if(!cnt[a[r]]) ans--;
r--;
}
while(l < q[i].l)
{
cnt[a[l]]--;
if(!cnt[a[l]]) ans--;
l = -(~l);
}
while(l > q[i].l)
{
l--;
if(!cnt[a[l]]) ans = -(~ans);
cnt[a[l]] = -(~cnt[a[l]]);
}
as[q[i].xs] = ans;
}
for(i = 1; i <= tot; i = -(~i))
{
printf("%d\n", as[i]);
}
return 0;
}