https://www.lydsy.com/JudgeOnline/problem.php?id=2120
In the title there are two different methods.
With modified Mo team and ordinary Mo team more than a modification operation, the impact is not big, but notice the details do not appear zz error.
The number of revisions to the problem can be written in the team, but it is probably not possible to modify the numbers or the extreme data.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 Const intmaxn=10010;7 using namespacestd;8 intn,m;9 Charch[3]={};Ten intclo[maxn]={},las[maxn]={}; One structnode{ A intPos,clo,pre; -}T[MAXN];intTr=0; - structnod{ the intL,r,id,pre; -}Q[MAXN];inttq=0; - intb[maxn]={},ans[maxn]={},ans1=0; - intvis[maxn* -]={}; + BOOLmcmp (nod Aa,nod bb) { - return(B[AA.L]==B[BB.L])? ((AA.R==BB.R) AA.ID<BB.ID:AA.R<BB.R):(b[aa.l]<B[BB.L]); + } A voidDoitintXintv) { at if(v) { - if(!vis[clo[x]]) ans1++; -vis[clo[x]]++; - } - Else{ - if(vis[clo[x]]==1) ans1--; invis[clo[x]]--; - } to } + voidChangeintXintYintv) { - //cout<<x<<y<<clo[x]<<v<<endl; the if(v) { *Doit (x,0); $clo[x]=y;Panax NotoginsengDoit (x,1); -}clo[x]=y; the } + voidWork () { A intL=1, r=0, now=0; the for(intI=1; i<=tq;i++){ + while(Now<q[i].pre) {Now++;change (t[now].pos,t[now].clo,l<=t[now].pos&&t[now].pos<=r);} - while(Now>q[i].pre) {Change (t[now].pos,t[now].pre,l<=t[now].pos&&t[now].pos<=r); now--;} $ while(R<Q[I].R) doit (++r,1); $ while(L>Q[I].L) doit (--l,1); - while(R>Q[I].R) {doit (R,0);--R;} - while(L<Q[I].L) {doit (L,0);++l;} theans[q[i].id]=ans1; - }Wuyi for(intI=1; i<=tq;i++){ theprintf"%d\n", Ans[i]); - } Wu } - intMain () { Aboutscanf"%d%d",&n,&m); $ for(intI=1; i<=n;i++) {scanf ("%d", &clo[i]); las[i]=clo[i];} - intx, y; - for(intI=1; i<=m;i++){ -scanf"%s", ch); scanf ("%d%d",&x,&y); A if(ch[0]=='Q'{q[++tq].l=x; q[tq].r=y; q[tq].id=tq; q[tq].pre=tr;} + Else{t[++tr].pos=x; t[tr].clo=y;t[tr].pre=las[x];las[x]=y;} the}intSiz= (int) sqrt (Double) n); - for(intI=1; i<=n;i++) b[i]= (i-1)/siz+1; $Sort (q+1, q+1+tq,mcmp); the Work (); the return 0; the}
View Code
Bzoj 2120: Number of colors with modified MO team Algorithm tree array set Chairman tree