Bzoj 2120: Number of colors with modified MO team Algorithm tree array set Chairman tree

Source: Internet
Author: User

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&LT;BB.ID:AA.R&LT;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&LT;Q[I].R) doit (++r,1); $          while(L&GT;Q[I].L) doit (--l,1); -          while(R&GT;Q[I].R) {doit (R,0);--R;} -          while(L&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.