3211: The flower God travels the country time Limit:5 Sec Memory limit:128 MB
submit:1042 solved:381
[Submit] [Status] Description Input Output
Each time x=1, an integer per line indicates the pleasure of this trip
Sample Input4
1 100 5 5
5
1 1 2
2 1 2
1 1 2
2 2 3
1 1 4
Sample Output101
11
11
HINT
For 100% data, n≤100000,m≤200000, Data[i] is non-negative and less than 10^9
Source
SPOJ2713 GSS4 data has been enhanced
The puzzle: Hum!!! Sure enough is the data of the enhanced version, but it is still the AC again (hansbug: ^_^, eh? What about Phile recently? In fact, and "God made 7 minutes 2" Basically the same, is its enhanced version, the focus is to deal with the optimization of some unnecessary operations can be (such as when a certain interval of the number of all <=1 ha hehe), specifically no longer repeat, see my Code Template: line segment Tree 5 (Portal here)
1 var2 I,j,k,l,m,n:longint;3B:Array[0..1000000] 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 the if(x=y) Then - begin - read (a[z]); - ifa[z]<=1 Thenb[z]:=1 Elseb[z]:=0; + End - Else + begin ABuilt (z*2, X, (X+y)Div 2); atBuilt (z*2+1, (X+y)Div 2+1, y); -a[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; in varA2,a3:int64; - begin to ifL>r ThenExit0); + ifb[z]=1 ThenExit0); - if(x=l) and(Y=R) and(L=R) Then the begin *a2:=A[z]; $a[z]:=trunc (sqrt (a[z));Panax Notoginseng ifa[z]<=1 Thenb[z]:=1; -Exit (a[z]-A2); the End; +A2:=op (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2)); AA3:=op (z*2+1, (X+y)Div 2+1, Y,max ((x+y)Div 2+1, L), R); thea[z]:=a[z]+a2+A3; + 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; - varA2,a3:int64; - begin the ifL>r ThenExit0); - if(x=l) and(Y=R) Thenexit (A[z]);WuyiA2:=cal (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2)); theA3:=cal (z*2+1, (X+y)Div 2+1, Y,max ((x+y)Div 2+1, L), R); -Exit (a2+A3); Wu End; - begin About READLN (n); $Built1,1, n); - Readln; - Readln (m); - fori:=1 toM Do A begin + readln (j,k,l); the CaseJ of - 1: Writeln (Cal (1,1, n,k,l)); $ 2: OP (1,1, n,k,l); the End; the End; the Readln; the End. -
3211: The flower God travels the country