代码:
#include<bits/stdc++.h>//我嘞个c++
using namespace std;
#define int long long
#define endl '\n'
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define lowbit(x) x&(-x)
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch > 57 || ch < 48)
{
if(ch == 45) f = -1;
ch = getchar();
}
while(ch >= 48 && ch <= 57)
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
int n, q;
int a[1000010];
int b[1000010];
int cnt;
struct nod
{
char c;
int l, r;
}f[1000010];
inline bool cmp(nod u, nod v)
{
return u.r == v.r ? (u.l < v.l) : (u.r < v.r);
}
signed main(void)
{
// freopen("1.in","r",stdin);
n = read(), q = read();
for(int i = 1;i <= n;++i) a[i] = read();
int l = f[1].r, r = f[1].r;
cnt = 1, b[a[f[1].r]]++;
for(int i = 1;i <= q;++i)
{
cin >> f[i].c;
f[i].l = read(), f[i].r = read();
if(f[i].c == 'R')
{
if(f[i].l >= l && f[i].l <= r)
{
--b[a[f[i].l]];
if(!b[a[f[i].l]]) ++cnt;
if(!b[f[i].r]) ++cnt;
++b[f[i].r];
}
a[f[i].l] = f[i].r;
continue;
}
while(l < f[i].l)
{
if(!(b[a[l]] ^ 1)) --cnt;
--b[a[l++]];
}
while(l > f[i].l)
{
if(!b[a[--l]]) ++cnt;
++b[a[l]];
}
while(r < f[i].r)
{
if(!b[a[++r]]) ++cnt;
++b[a[r]];
}
while(r > f[i].r)
{
if(!(b[a[r]]^1)) --cnt;
--b[a[r--]];
}
printf("%lld\n",cnt);
}
return 0;
}