Version-Controlled IDE
Time limit1sMemory limit128 MB
Maintain a versioned text buffer under insert and delete operations, answering substring queries against any past version, with all commands encoded by a running counter.
- Level
Hard9 of 10
- Topics
- Tree, Implementation, String, Brute force
- Solved
- No attempts yet
Problem
Many programmers use a version control system to manage the files in a project. Such systems have a drawback, however: a version is recorded only when the user explicitly saves.
Here you will implement an IDE that automatically saves a new version every time a string is inserted or deleted.
Positions in the buffer are numbered from left to right starting at 1. Initially the buffer is empty and the version number is 0.
Let be the length of the buffer at version , and let be the version number just before a command is executed. The IDE supports three commands:
1 p s: insert the string right after position (). If , insert at the very front of the buffer. The length of is between 1 and 100.2 p c: delete characters starting at position (, ).3 v p c: output characters starting at position in version (, ).
The first command is always a type-1 command. Executing a type-1 or type-2 command increases the version by 1; a type-3 command does not change the version.
Input
The first line contains the number of commands (). Each of the next lines contains one command. The total length of all inserted strings does not exceed .
To prevent preprocessing the input, each command is encoded. Let be the number of lowercase c characters printed so far (initially ).
- A type-1 command is given as
1 p+d s, - a type-2 command is given as
2 p+d c+d, - a type-3 command is given as
3 v+d p+d c+d.
So after reading each command, subtract from every numeric argument to recover the real values , , and .
Output
Every time a type-3 command is executed, print its resulting string on its own line. The total length of the printed strings does not exceed .