Constructing the Array
MediumRating 1600CodeforcesDesign Data Structures
Approach hintTry it first, then revealHide
Keep the zero segments in a priority queue ordered by length descending, then by left border ascending. Each step pops one segment, writes the next number at its middle and pushes the two remaining pieces.