![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <algorithm> #include <cstdio> #include <cmath> using namespace std; const int N(110); int n,m,col[N*N]; #define MAX(a,b) (a>b?a:b) #define MIN(a,b) (a<b?a:b) int cnt,str[N],ove[N],bel[N]; int now[N*N],cc[N][N*N],sum[N]; void Build() { int C=sqrt(n); for(int i=1;i<=n;i+=C) { str[++cnt]=i; ove[cnt]=MIN(n,i+C-1); } for(int i=1;i<=cnt;i++) for(int j=str[i];j<=ove[i];bel[j++]=i) if(!cc[i][col[j]]) cc[cnt][col[j]]++,sum[i]++; } void Change(int u,int x) { if(!cc[bel[u]][x]) sum[bel[u]]++; cc[bel[u]][x]++; } int Query(int u,int v) { int ret=0; for(int i=bel[u];i<=bel[v];i++) if(str[i]>=u&&ove[i]<=v) ret+=sum[i]; else for(int j=MAX(str[i],u);j<=MIN(ove[i]);j++) ret+= } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",col+i),now[i]=col[i]; Build(); for(char ch[2];m--;) { scanf("%s%d%d",ch,&u,&v); if(ch[0]=='R') Change(u,v); else printf("%d ",Query(u,v)); } return 0; }