3401: [Usaco2009 mar]look up

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.