highs := {Map[First, #], Most[FoldList[Plus, 1, Map[Length, #]]]} &[
Split[Rest[FoldList[Max, -\[Infinity], #]]]] &;
lows := {Map[First, #], Most[FoldList[Plus, 1, Map[Length, #]]]} &[
Split[Rest[FoldList[Min, +\[Infinity], #]]]] &;
seqS = Table[N[FractionalPart[Tan[n]], 20], {n, 1, 1000}];
(* User:put your dense sequence S after seqS *)
indices = Range[Length[seqS]];
arrI = {}; (*start accumulating increasing partition array*)
Until[Last[arrI] == {}, AppendTo[arrI, Flatten[Map[Position[seqS, #] &,
highs[seqS[[Complement[indices, Flatten[arrI]]]]][[1]]]]]];
Grid[Take[arrI, 12]]
arrD = {}; (*start accumulating decreasing partition array*)
Until[Last[arrD] == {}, AppendTo[arrD, Flatten[Map[Position[seqS, #] &,
lows[seqS[[Complement[indices, Flatten[arrD]]]]][[1]]]]]];
Grid[Take[arrD, 12]]
(*_Peter J.C.Moses_, Sep 04 2025*)