APL (Dyalog Unicode), 34 bytesSBCS
Anonymous prefix lambda.
{∊((⊃⍴⍨2|≢),+⍨⍴⍨∘⌊2÷⍨≢)¨⍵⊂⍨2≠/0,⍵}
[Try it online!][TIO-jq3pxrjk]Try it online!
{
…}
dfn; ⍵
is right argument
0,⍵
prepend a zero to the argument
2≠/
pairwise inequality mask
⍵⊂⍨
use that to partition (true means begin new partition here) the argument
(
…)¨
apply the following tacit function to each run of equal numbers:
≢
the length of the run
2÷⍨
let 2 divide that
⌊
floor that
∘
then
⍴⍨
use it to reshape…
+⍨
the doubled (lit. addition selfie) run
(
…),
append that to the following:
≢
the length of the run
2|
division remainder when divided by two (1 for odd length runs, 0 for even length runs)
⊃⍴⍨
use that to reshape the first element of the run
∊
enlist (flatten)
[TIO-jq3pxrjk]: https://tio.run/##SyzI0U2pTMzJT///v/pRR5eGRp1RzaPORZqP2iY/6mrW0X7Uu@JR7xYQ2THjUU@X0eHtIDZQwSGg@NZHXU1ArtGjzgX6BjpAfu3/tEdtEx719j3qm@rpDzTg0HrjR20TgbzgIGcgGeLhGfw/TeFR7xquNAUjHRAyASI4B8rXUbBAFjICciDCQI4FGIGEDA2MgEIQ0tTQCEoYmZqBCaACYx0oMgQjc6AKOAIA"APL (Dyalog Unicode) – Try It Online"