<题意概括>
又是一道莫队模板题
<做法>
既然是莫队模板题那当然是Ctrl+V啦2333
<Code>
#include<cstdio> #include<algorithm> #include<cmath> #define Fast register inline char Getchar(){ static char BUF[16384],*S=BUF,*T=BUF; return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++; } inline int Getint(){ Fast int s=0;Fast char c=Getchar(); while(c<48||c>57)c=Getchar(); while(c>47&&c<58)s=s*10+c-48,c=Getchar(); return s; } inline char Getopt(){ Fast char c=Getchar(); while(c!=‘Q‘&&c!=‘R‘)c=Getchar(); return c; } int Block[10001]; int Cnt_Query,Cnt_Change; struct Query{ int L,R,ID,Time; Query():L(0),R(0),ID(0),Time(0){} Query(const int&l,const int&r,const int&id,const int&t):L(l),R(r),ID(id),Time(t){} inline bool operator<(const Query&T)const{return Block[L]==Block[T.L]?(Block[R]==Block[T.R]?Time<T.Time:R<T.R):L<T.L;} }query[10001]; struct Change{ int Pos,Old,New; Change():Pos(0),Old(0),New(0){} Change(const int&P,const int&O,const int&N):Pos(P),Old(O),New(N){} }change[1001]; int Cnt[1000001]; int COLOR[10001]; int Now[10001]; int Answer,L=1,R,Time; int Ans[10001]; inline void update(const int&Color,const int&Delta){ Cnt[Color]+=Delta; if(Delta<0)Answer-=!Cnt[Color]; if(Delta>0)Answer+=Cnt[Color]==1; } inline void Modify(const int&Pos,const int&Color){ if(L<=Pos&&Pos<=R)update(Color,1),update(COLOR[Pos],-1); COLOR[Pos]=Color; } #define Qi (query+i) int main(){ Fast int N=Getint(),M=Getint(),l,r; Fast char c; Fast int Unit=pow(N,0.6666666666666666666666666); for(Fast int i=1;i<=N;++i)COLOR[i]=Now[i]=Getint(),Block[i]=i/Unit+1; for(Fast int i=1;i<=M;++i){ c=Getopt();l=Getint(),r=Getint(); if(c==‘Q‘)query[++Cnt_Query]=Query(l,r,Cnt_Query,Cnt_Change); else change[++Cnt_Change]=Change(l,Now[l],r),Now[l]=r; } std::sort(query+1,query+Cnt_Query+1); for(Fast int i=1;i<=Cnt_Query;++i){ while(Time<Qi->Time)++Time,Modify(change[Time].Pos,change[Time].New); while(Time>Qi->Time)Modify(change[Time].Pos,change[Time].Old),--Time; while(L<Qi->L)update(COLOR[L++],-1); while(L>Qi->L)update(COLOR[--L],1); while(R<Qi->R)update(COLOR[++R],1); while(R>Qi->R)update(COLOR[R--],-1); Ans[Qi->ID]=Answer; } for(Fast int i=1;i<=Cnt_Query;++i)printf("%d\n",Ans[i]); return 0; }