Description
Solution
Tree-like array single-point modification interval query
We know that a number n is changed by a maximum of loglogn times to 1.
And check the set to maintain the first position on the right of each number is not 1
#include <cstdio>#include<iostream>#include<cstdlib>#include<cstring>#include<cmath>#defineMAXN 100005using namespaceStd;typedefLong LongLL;intN,M,DELTA[MAXN],FATHER[MAXN]; LL C[MAXN]; intRead () {intx=0, f=1;CharC=GetChar (); 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;}intLowbit (intx) {returnx&-x;}voidAddintPosintx) { while(pos<=N) {C[pos]+=x; POS+=Lowbit (POS); }}ll Query (intPOS) {LL res=0; while(pos>0) {res+=C[pos]; POS-=Lowbit (POS); } returnRes;}intFindintx) { if(X==father[x])returnx; FATHER[X]=find (father[x]); returnfather[x];}intMain () {n=read (); for(intI=1; i<=n;i++) {Delta[i]=read (); Add (I,delta[i]); Father[i]=i; } m=read (); for(intI=1; i<=m;i++) { intX=read (), L=read (), r=read (); if(x==1) printf ("%lld\n", query (R)-query (l1)); Else if(x==2) { for(intJ=l;j<=r&&j;j=find (j+1) {Add (J, (int) sqrt (Delta[j])-Delta[j]); DELTA[J]=(int) sqrt (delta[j]); if(delta[j]<=1) father[j]=j+1; } } } return 0;}
[Bzoj 3211] flower gods travel across countries (and set + Tree array)