realization function--1: Interval open root; 2: Interval summation (this template takes BZOJ3038 as an example)
As an unconventional segment tree operation, its tag is also more special Oh da
1 var2 I,j,k,l,m,n:longint;3B:Array[0..500000] ofInt64;4 functionMax (x,y:longint): Longint;inline;5 begin6 ifX>y ThenMax:=xElsemax:=y;7 End;8 functionmin (x,y:longint): Longint;inline;9 beginTen ifX<y ThenMin:=xElsemin:=y; One End; A procedurebuilt (z,x,y:longint), inline; - begin - ifX=y Then the begin - read (a[z]); - ifa[z]<=1 Thenb[z]:=1 Elseb[z]:=0; - End + Else - begin +Built (z*2, X, (X+y)Div 2); ABuilt (z*2+1, (X+y)Div 2+1, y); ata[z]:=a[z*2]+a[z*2+1]; - if(b[z*2]=1) and(b[z*2+1]=1) Thenb[z]:=1 Elseb[z]:=0; - End; - End; - functionop (z,x,y,l,r:longint): Int64;inline; - varA2,a3,a4:int64; in begin - ifL>r ThenExit0); to ifb[z]=1 ThenExit0); + if(x=l) and(Y=R) and(L=R) Then - begin thea2:=A[z]; *a[z]:=trunc (sqrt (a[z)); $ ifa[z]<=1 Thenb[z]:=1;Panax NotoginsengExit (a[z]-A2); - End; theA2:=op (z*2, X, (X+y)Div 2, L,min ((x+y)Div 2, R)); +A3:=op (z*2+1, (X+y)Div 2+1, Y,max ((x+y)Div 2+1, L), R); Aa[z]:=a[z]+a2+A3; the if(b[z*2]=1) and(b[z*2+1]=1) Thenb[z]:=1; +Exit (a2+A3); - End; $ functioncal (Z,x,y,l,r:longint): Int64;inline; $ begin - ifL>r ThenExit0); - if(x=l) and(Y=R) Thenexit (A[z]); theExit (Cal (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2)) +cal (z*2+1, (X+y)Div 2+1, Y,max ((x+y)Div 2+1, L), R); - End;Wuyi procedureSwapvarx,y:longint); inline; the varZ:longint; - begin Wuz:=x;x:=y;y:=Z; - End; About $ begin - READLN (n); -Built1,1, n); - Readln; A Readln (m); + fori:=1 toM Do the begin - readln (j,k,l); $ ifK>l Thenswap (k,l); the CaseJ of the 1: Writeln (Cal (1,1, n,k,l)); the 0: OP (1,1, n,k,l); the End; - End; in End. the
Algorithm template--segment Tree 5 (interval open root + interval summation)