There's nothing to say, tree chain split
Code
1#include <cstdio>2 #defineN 10000103 intDp,pre[n],p[n],tt[n],size[n],f[n],gf[n];4 intl[n],r[n],go[n],v[n],s[n],tot,m;5 intl[n],r[n],n,a,i;6 Charstr[Ten];7 voidLinkintXinty)8 {9dp++;p re[dp]=p[x];p [x]=dp;tt[dp]=y;Ten } One voidDFS1 (intXintFA) A { - intI=P[x]; -size[x]=1; the while(i) - { - DFS1 (tt[i],x); -size[x]+=Size[tt[i]]; +f[tt[i]]=x; - if(Size[tt[i]]>size[go[x]]) go[x]=Tt[i]; +I=Pre[i]; A } at } - voidDFS2 (intXintFA) - { - intI=P[x]; -l[x]=++tot; -gf[x]=FA; in if(Go[x]) DFS2 (GO[X],FA); - while(i) to { + if(tt[i]!=go[x]) DFS2 (Tt[i],tt[i]); -I=Pre[i]; the } *r[x]=tot; $ }Panax Notoginseng voidBuildintXintAintb) - { thel[x]=a;r[x]=b; + if(b-a>1) A { the intM= (L[x]+r[x]) >>1; +Build2*x,a,m); -Build2*x+1, m,b); $ } $ } - voidCleanintx) - { the if(v[x]!=-1) - {WuyiS[x]= (R[x]-l[x]) *V[x]; thev[2*x]=V[x]; -v[2*x+1]=V[x]; Wuv[x]=-1; - } About } $ voidChangeintXintAintBintc) - { - Clean (x); - if((A<=l[x]) && (r[x]<=b)) A { +v[x]=C; the return; - } $ intM= (L[x]+r[x]) >>1; the if(a<m) Change (2*x,a,b,c); the if(m<b) Change (2*x+1, a,b,c); theClean2*X); Clean (2*x+1); thes[x]=s[2*x]+s[2*x+1]; - } in intQueryintXintAintb) the { the Clean (x); About if((A<=l[x]) && (r[x]<=b)) the returnS[x]; the intM= (L[x]+r[x]) >>1, ans=0; the if(a<m) Ans+=query (2*x,a,b); + if(m<b) Ans+=query (2*x+1, A, b); - returnans; the }Bayi intGetans (intx) the { the intans=0; - while(x) - { the //printf ("%d%d\n", l[gf[x]],l[x]); theAns=ans+ (l[x]-l[gf[x]]+1)-query (1, l[gf[x]]-1, l[x]); theChange1, l[gf[x]]-1, L[x],1); thex=F[gf[x]]; - } the returnans; the } the intMain ()94 { thescanf"%d",&n); the for(i=2; i<=n;i++) the {98scanf"%d", &a); a++; About link (a,i); - }101DFS1 (1,0);102DFS2 (1,1);103Build1,0, tot);104scanf"%d",&m); the for(i=1; i<=m;i++)106 {107scanf"%s%d", str,&a); a++;108 if(str[0]=='I')109printf"%d\n", Getans (a)); the Else111 { the //printf ("%d%d\n", L[a],r[a]);113printf"%d\n", Query (1, l[a]-1, R[a])); theChange1, l[a]-1, R[a],0); the } the }117}
bzoj4196 [NOI2015] Package Manager