Bzoj 2120 Number of colors &2453 maintenance queue [with modified MO team algorithm] "Learning notes"

Source: Internet
Author: User

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&LT;A.TIM:POS[R]&LT;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&LT;Q[I].R) r++, add (A[r]);  while(R&GT;Q[I].R) del (A[r]), r--;  while(L&LT;Q[I].L) del (A[l]), l++;  while(L&GT;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"

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.