3401: [Usaco2009 mar]look up look time limit:3 Sec Memory limit:128 MB
submit:136 solved:81
[Submit] [Status] [Discuss] Description John's N (1≤n≤105) cow stood in a row, and the cow I was tall (l≤hi≤1,000,000). Now, every cow is on the left. For cow I, if cow J satisfies i<j and hi6
3
2
6
1
1
2Sample Output3
3
0
6
6
0HINT Source
Silver
Puzzle: Once again, please out of my magical small line tree-the implementation of a segment tree to find in a position after a value of the most left position, with a more magical division, concrete as the program (found that the line is a mess of artifacts ah have wood)
1 var2 I,j,k,l,m,n:longint;3B:Array[0..1000000] ofLongint;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]); -b[x]:=A[z]; - End + Else - begin +Built (z*2, X, (X+y)Div 2); ABuilt (z*2+1, (X+y)Div 2+1, y); atA[z]:=max (a[z*2],a[z*2+1]); - End; - End; - functionapproach (z,x,y,l,r,t:longint): Longint;inline; - varA1:longint; - begin in ifL>r ThenExit0); - ifA[z]<=t ThenExit0); to ifX=y Then + begin - ifA[z]>t Thenexit (x); the End; *A1:=approach (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2), t); $ ifA1<>0 Thenexit (A1);Panax NotoginsengExit (Approach (z*2+1, (X+y)Div 2+1, Y,max ((x+y)Div 2+1, L), r,t)); - End; the begin + READLN (n); ABuilt1,1, n); the fori:=1 toN Do +Writeln (Approach (1,1, n,i+1, N,b[i])); - $ End.
3401: [Usaco2009 mar]look up