Editorial for Max's Anger Contest Series 1 P3 - Divide and Connor


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: maxcruickshanks

It suffices to naively divide and conquer: at each level, store all the current elements in an auxiliary array.

Now, write all the elements from the last third of the auxiliary array to the first third of the array. Then, write all the elements from the first third of the auxiliary array to the middle third of the array. Next, write all the elements from the middle third of the auxiliary array to the last third of the array.

Finally, output the final array after repeating this at each level.

Time Complexity: \mathcal{O}(N \log N)


Comments

There are no comments at the moment.