String Insert and Print
Time limit10sMemory limit256 MB
Maintain a single string under positional insertions and print the requested substring for each query.
- Level
Medium6 of 10
- Topics
- Tree, String, Implementation
- Solved
- No attempts yet
Problem
Keep one string and process insert operations and print operations in the order they are given. An insert operation puts a new string into a chosen position of , and a print operation writes out a chosen range of exactly as it stands. No clever idea is needed here, only implementation.
Input
The first line contains the number of test cases . ()
The first line of each test case contains a string . ()
The operations follow, one per line, and there is at least one operation line. Indices start at 0.
I R X: insert the string into at index . () After the insertion the first character of sits at index . When , is appended to the end of . For example, when isabc,I xy 1givesaxybc,I xy 3givesabcxy, andI xy 0givesxyabc.P X Y: print the characters of from index through index . () For example, when isabc,P 0 2printsabcandP 1 1printsb.END: the test case ends here.
and consist of lowercase letters only. The length of never passes 1,000,000 while the operations run, and the number of printed characters summed over all test cases never passes 1,000,000.
The input and the output are both large, so fast input and output are worth using.
Output
Every time a P X Y operation appears, print the matching substring on its own line.