莫队WA+TLE-->0pts
#include<bits/stdc++.h>
#define ll long long
#define For( i , a , b ) for( register ll i = ( a ) ; i <= ( b ) ; ++i )
#define Rep( i , a , b ) for( register ll i = ( a ) ; i >= ( b ) ; --i )
using namespace std ;
inline ll read() {
ll s = 0 ; char ch = getchar() ; bool f = 0 ;
for( ; !isdigit( ch ) ; ch = getchar() ) f ^= !( 45 ^ ch ) ;
for( ; isdigit( ch ) ; ch = getchar() ) s = ( s << 3 ) + ( s << 1 ) + ( ch ^ 48 ) ;
if( f ) return -s ; return s ;
}
const int N = 143335 ;
int n , b , a[ N ] , ans[ N ] , cnt1 , cnt2 , Q ;
struct node{
int L , R , T , id ;
} t[ N ] , c[ N ] ;
bool cmp( node x1 , node x2 ) {
if( x1.L / b != x2.L / b ) return x1.L < x2.L ;
else if( x1.R / b != x2.R / b ) return x2.R < x2.R ;
else return x1.T < x2.T ;
}
int l = 1 , r = 0 , ti = 0 , cnt[ N ] , now ;
inline void del( int x ) {
cnt[ a[ x ] ] -- ;
if( ! cnt[ a[ x ] ] ) now -- ;
}
inline void add( int x ) {
if( ! cnt[ a[ x ] ] ) now ++ ;
cnt[ a[ x ] ] ++ ;
}
inline void cha( int x ) {
if( l <= c[ x ].L && c[ x ].L <= r ) {
cnt[ a[ c[ x ].L ] ] -- ;
if( !cnt[ a[ c[ x ].L ] ] ) -- now ;
if( !cnt[ c[ x ].R ] ) ++now ;
cnt[ c[ x ].R ] ++ ;
}
swap( a[ c[ x ].L ] , c[ x ].R ) ;
}
inline void moveto( int x ) {
while( l > t[ x ].L ) add( -- l ) ;
while( l < t[ x ].L ) del( l ++ ) ;
while( r > t[ x ].R ) del( r -- ) ;
while( r < t[ x ].R ) add( ++ r ) ;
while( ti > t[ x ].T ) cha( ti -- ) ;
while( ti < t[ x ].T ) cha( ++ ti ) ;
}
int main() {
// freopen("t.in" , "r" , stdin ) ;
// freopen("t1.out" , "w" , stdout ) ;
n = read() ; b = pow( n , 0.66666666 ) ; Q = read() ;
For( i , 1 , n ) a[ i ] = read() ;
For( i , 1 , Q ) {
char ch = getchar() ; while( ch != 'Q' && ch != 'R' ) ch = getchar() ;
if( ch == 'Q' ) t[ ++cnt1 ].L = read() , t[ cnt1 ].R = read() , t[ cnt1 ].id = cnt1 , t[ cnt1 ].T = cnt2 ;
else c[ ++cnt2 ].L = read() , c[ cnt2 ].R = read() ;
}
sort( t + 1 , t + 1 + cnt1 , cmp ) ;
For( i , 1 , cnt1 ) {
// if( !( i % 10000 ) ) cout<< i << '\n' ;
//cout << t[ i ].L << " " << t[ i ].R << " " << t[ i ].T << endl ;
moveto( i ) ;
ans[ t[ i ].id ] = now ;
}
For( i , 1 , cnt1 ) printf("%d\n" , ans[ i ] ) ;
return 0 ;
}
/*
6 7
1 2 3 4 5 5
Q 1 4
Q 2 6
Q 5 6
R 6 8
Q 5 6
Q 1 4
Q 2 6
*/