a = {1, 5, 10, 200, 50, 7};
b = {4, 3, 19, 78};
Position[#, -1, 1, 1] & /@ (Sign@(# - b) & /@ a) /. {} -> {0} // Flatten
(* {1, 3, 3, 0, 4, 3} *)
Update: Per whuber's suggestion, removing out-of-order elements from b
, and re-mapping position numbers using a parallel list of position indices:
With[{b0 = FoldList[Max, First@b, Rest@b]},
indices = Pick[Range@Length@b, MapThread[ Equal, {b, b0}]];
(Position[#, -1, 1, 1] & /@ (Sign@(# - Union@b0) & /@ a) /. {} -> {{0}} // Flatten)
/.Thread[Range@Length@indices -> indices]]
Few more alternatives for creating indices
:
indices2 = Pick[Range@Length@b, Equal @@@ Transpose[{b, b0}]]
(* as suggested by J.M: *)
indices3=Fold[If[#1 === {}||Last[b[[#1]]] < b[[#2]],Append[#1, #2], #1] &,{},
Range[Length[b]]]