Test instructions
Ask the number of different colors in the interval, change the color of the single point
found that the previous written study notes can not be read, so rewrite (not to use latex)
Additional maintenance of the time at which a current modification operation was performed
If you want to make a query operation, the time to modify the operation must be moved to this query operation
Sort by $ (pos[l], Pos[r], Tim) $
Make $s=n^{\frac{2}{3}}$, have $n^{\frac{1}{3}}$ block
$l $ move $n*n^{\frac{2}{3}}$ times
$r $ move $n*n^{\frac{1}{3}}+n*n^{\frac{2}{3}}$ times
$cur $ move $n*n^{\frac{1}{3}}*n^{\frac{1}{3}}$ times
Note the sorting must be right.
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong Longll;Const intn=1e4+5, m=1e6+5; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;} intn,q,a[n],pos[n],m,block,t[n],x,y;Charop[3];structmeow{intL,r,tim,id; BOOL operator< (ConstMeow &a)Const{ returnPOS[L]==POS[A.L]? (POS[R]==POS[A.R]? TIM<A.TIM:POS[R]<POS[A.R]): pos[l]<POS[A.L]; }}q[n];structcmeow{intP,v,last;} Cq[n];intP,tim, ans[n];intC[m], now;intL=1, r=0, cur=0; inlinevoidAddintx) {now+= (++c[x]) = =1;} InlinevoidDelintx) {now-= (--c[x]) = =0;} InlinevoidChaintPintv) { if(L<=p && p<=r) Add (v), Del (A[p]); A[P]=v;}voidModui () { for(intI=1; i<=p;i++){ while(Cur<q[i].tim) cur++, Cha (cq[cur].p, CQ[CUR].V); while(Cur>q[i].tim) Cha (cq[cur].p, cq[cur].last), cur--; while(R<Q[I].R) r++, add (A[r]); while(R>Q[I].R) del (A[r]), r--; while(L<Q[I].L) del (A[l]), l++; while(L>Q[I].L) l--, add (A[l]); ans[Q[i].id]=Now ; }}intMain () {//freopen ("in", "R", stdin);N=read (); q=read (); Block=SQRT (n); M= (n1)/block+1; for(intI=1; i<=n;i++) A[i]=t[i]=read (), pos[i]= (i-1)/block+1; for(intI=1; i<=q;i++) {scanf ("%s", op); X=read (); y=read (); if(op[0]=='Q') q[++p]=(meow) {x, Y, Tim, p}; ElseCq[++tim]= (Cmeow) {x, Y, T[x]}, t[x]=y; } sort (Q+1, q+1+p); Modui (); for(intI=1; i<=p;i++) printf ("%d\n", Ans[i]);}
Bzoj 2120 Number of colors &2453 maintenance queue [with modified MO team algorithm] "Learning notes"