Editorial for Arcadia Computing Contest 1 P4 - Cyclic Sorting
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Let's define a decrease as a point where .
Maintain a set data structure, keeping track of the position of decreases (including the last and first element of the array). Then. for every query, update the set. If the number of decreases is exactly or , it is possible. Otherwise, it is not.
If it is equal to , the number of shifts necessary is simply where denotes the index of the decrease.
Comments