Editorial for IOI '12 P3 - Crayfish Scrivener
Submitting an official solution before solving the problem yourself is a bannable offence.
A clever way to get an efficient solution consists in representing the evolution of the system through a trie, containing all the contents of the text so far; a point in time is represented by a single pointer to a node in the trie.
Command processing requires time:
- typing a letter just requires moving down in the trie (creating a new node if necessary)
- undoing commands requires moving states back.
For all the subtasks except the final one, after processing all the commands, the final contents can be extracted from the trie into an array and used to answer queries in time, giving time and space overall.
Subtask 5 requires a definitely more sophisticated approach to find a point in the text. For this it is sufficient to be able to determine the -ancestor of the current node: There are a number of standard data structures for this problem that give time overall. For example, every node at depth can contain a pointer to its -th ancestor, where is the position of the rightmost in the binary expansion of .
Comments