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<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