A Simple Task
HardRating 2300CodeforcesSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
Sorting a range needs only the number of each letter inside it. Keep 26 segment trees, or one storing 26 counts, with lazy range assignment: count letters in [i, j], then rewrite the range as consecutive blocks.