Text Editor
Time limit1sMemory limit150 MB
Implement a text editor over a string up to 2^63 characters with insert, erase, cut, paste, undo, redo, and a two-run serialize step.
- Level
Hard9 of 10
- Topics
- Tree, Implementation, Simulation
- Solved
- No attempts yet
Problem
This is a run-twice problem: your solution is executed twice on each test. See the rest of the statement and the input format section for more details.
Your task is to implement a simple text editor that works with strings of characters with values in range to and implements the interface described below. The length of the string is guaranteed to be at most at all times. All parameters of the commands are -indexed and all intervals are semi-open: is included while is excluded. All intervals are nonempty, and all positions and intervals are within bounds. The clipboard is initially empty.
insert: inserts string at the -th position of the file. The total length of all is at most .erase: erases the contents of the file from the -th to the -th character.print: prints the contents of the file from the -th to the -th character. The total length of the output for allprintcommands does not exceed .copy: copies the contents of the file from the -th to the -th character to the clipboard.cut: cuts the contents of the file from the -th to the -th character to the clipboard.paste: inserts the contents of the clipboard at the -th position of the file. An empty clipboard is never pasted.serialize: writes the contents of the file (but not the clipboard) to the output. The output must not exceed characters and may use only characters in the range to . The output string does not have to represent the contents of the file exactly, but your program must be able to recreate the file in response todeserialize. You must print at least one character. This command is issued only once, as the last command of the first run.deserialize: is exactly the string printed in response toserialize. This command is issued only once, as the first command of the second run.undo: rolls back the changes made by the last command that changed the contents of the file (insert,erase,cut,paste, ordeserialize), leaving the clipboard unchanged. If there is no previous version, the command does nothing.redo: redoes the last undo that is not yet undone. If there is no next version, the command does nothing. As in most text editors, any command that changes the file also erases all next versions. Other commands, such ascopy, do not.
Input
The first line contains a single integer (), the number of commands. The next lines contain the commands in the format described above. The input format is the same for both runs.
Output
Print the answers to all print and serialize commands, each on a separate line.