Editorial for DMOPC '21 Contest 3 P4 - Sorting Subsequences
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
Let's imagine the array as a line of nodes. We add a directed edge from
By the definition of lexicographical minimum, we want to minimize the value of the first element, then the second, and so on. Therefore, the first thing we want to do is to draw an edge from
Note that as we move through this process, we will form chains of directed edges connecting the nodes together. We know that it is possible to draw an edge from
and are part of different chains, and the combined number of nodes in the chains does not exceed . and are part of the same chain, and connecting to completes a directed cycle.
It is possible to directly simulate this process with a nested for-loop, maintaining the necessary information with DSU.
Time Complexity:
Subtask 2
Instead of the inner for-loop from the previous solution, we can simulate it with a segment tree indexed by values that stores the size of the component for each value (for example,
Time Complexity:
Comments