eolymp
bolt
Try our new interface for solving problems
Problems

Version Controlled IDE

Version Controlled IDE

Programmers use version control systems to manage files in their projects, but in these systems, versions are saved only when you manually submit. Can you implement an IDE that automatically saves a new version whenever you insert or delete a string? Positions in the buffer are numbered from \textbf{1} from left to right. Initially, the buffer is empty and in version \textbf{0}. Then you can execute \textbf{3} commands (vnow means the version before executing the command, and \textbf{L\[v\]} means the length of buffer at version \textbf{v}): \textbf{1 p s}: insert string \textbf{s} after position \textbf{p} (\textbf{0} ≤ \textbf{p} ≤ \textbf{L\[vnow\]}, \textbf{p=0} means insert before the start of the buffer). \textbf{s} contains at most \textbf{1} and at most \textbf{100} letters. \textbf{2 p c}: remove \textbf{c} characters starting at position \textbf{p} (\textbf{p} ≥ \textbf{1}, \textbf{p+c} ≤ \textbf{L\[vnow\]+1}). The remaining charactesr (if any) will be shifted left, filling the blank \textbf{3 v p c}: print \textbf{c} characters starting at position \textbf{p} (\textbf{p} ≥ \textbf{1}, \textbf{p+c} ≤ \textbf{L\[v\]+1}), in version \textbf{v} (\textbf{1} ≤ \textbf{v} ≤ \textbf{vnow}). The first command is guaranteed to be command \textbf{1} (insert). After executing each command \textbf{1} or \textbf{2}, version is incremented by \textbf{1}. \InputFile There is only one test case. It begins with a single integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{50000}), the number of commands. Each of the following \textbf{n} lines contains a command. The total length of all inserted string will not exceed \textbf{1000000}. \OutputFile Print the results of command \textbf{3}, in order. The total length of all printed strings will not exceed \textbf{200000}. \textit{\textbf{Obfuscation}} In order to prevent you from preprocessing the command, we adopt the following obfuscation scheme: Each type-\textbf{1} command becomes \textbf{1 p+d s} Each type-\textbf{2} command becomes \textbf{2 p+d c+d} Each type-\textbf{3} command becomes \textbf{3 v+d p+d c+d} Where \textbf{d} is the number of lowercase letter '\textbf{c}' you printed, before processing this command. After the obfuscation, the sample input would be: \textbf{6} \textbf{1 0 abcdefgh} \textbf{2 4 3} \textbf{3 1 2 5} \textbf{3 3 3 4} \textbf{1 4 xy} \textbf{3 5 4 6} This is the real input that your program will read.
Time limit 8 seconds
Memory limit 64 MiB
Input example #1
6
1 0 abcdefgh
2 4 3
3 1 2 5
3 2 2 3
1 2 xy
3 3 2 4
Output example #1
bcdef
bcg
bxyc
Source ACM-ICPC Asia Hatyai Regional Programming Contest – November 16, 2012 – PSU, Hatyai