OPTIMAL CONSTRUCTION OF A LAYER-ORDERED HEAP AND ITS APPLICATIONS