"cf56e" Domino Principle

Source: Internet
Author: User

Each Domino's position is set to X, and the domino height is h per block . If you turn the Domino on the X position to the right , it will affect all the dominoes in the [X+1, X+h-1] range , and let them also turn over, while these are turned into dominoes it can also affect other dominoes , and now Bsny gives the position and height of the N-block dominoes, asking how many dominoes will turn up if you turn right into block I dominoes.

Sort by left endpoint, then linear scan. In fact, two points can be, but the answer has part of the overlap, that is monotonic.

1 varX,h,d,c,ans:Array[1..200000] ofLongint;2 N,i,k,last:longint;3  4 procedureSwapvarx,y:longint);5 varT:longint;6 begin7T:=x; X:=y; y:=T;8 End;9  Ten procedureqsort (l,r:longint); One varI,j,mid:longint; A begin -I:=l; J:=r; mid:=x[(l+r) >>1]; -  Repeat the    whileMid>x[i] DoInc (i); -    whileMID&LT;X[J] DoDec (j); -   ifI<=j Then -   begin + swap (x[i],x[j]); - swap (h[i],h[j]); + swap (c[i],c[j]); A swap (d[i],d[j]); at Inc (I); Dec (j); -   End; -  untilI>J; -  ifL<j Thenqsort (l,j); -  ifI<r Thenqsort (i,r); - End; in   - begin to    + READLN (n); -   fori:=1  toN Do the  begin * readln (X[i],h[i]); $d[i]:=x[i]+h[i]-1;Panax Notoginsengc[i]:=i; -  End; theQsort1, n); +ans[c[n]]:=1; A   fori:=n-1 Downto 1  Do the  begin +last:=D[i]; -k:=i+1; $ans[c[i]]:=1; $    whileTrue Do -   begin -    ifK>n ThenBreak ; the    ifX[k]<=last Thenans[c[i]]:=ans[c[i]]+Ans[c[k]] -     ElseBreak ;Wuyik:=k+Ans[c[k]]; the   End; -  End; Wu   fori:=1  toN-1  DoWrite (Ans[i],' '); - Writeln (Ans[n]); About   $ End.
View Code

"cf56e" Domino Principle

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.