수 메가바이트까지 커지는 문자열에서 삽입, 삭제, 이동, 출력 연산을 수행하는 텍스트 편집기를 시뮬레이션한다. 단순 배열 이동으로는 시간 안에 끝나지 않는다.
어려움8연결 리스트구현시뮬레이션배열아직 제출이 없습니다시간 제한2초메모리 제한256 MBA long, long time ago, DOS3.x programmers were starting to get tired of EDLIN. So they gradually switched to editors that they wrote themselves.
Many years later, Alex has accidentally stumbled upon a text editor from back in these days. After some basic testing, he has made a shocking discovery: this software is able to perform tens of thousands of edit operations per second (of course, you cannot conduct these tests by hand)! So, Alex is spending sleepless nights trying to create a product like this himself. Can you help him?
To clarify the objective, Alex has created some definitions to make the term "text editor" less abstract:
| Operation | Input Format | Function |
|---|---|---|
| Move(k) | Move k | Moves the cursor's position to immediately after the k-th character in the text. If k= 0, then the cursor is moved to the start of the text. |
Insert(n, s) | Insert n↵ s | Inserts a string s of length n (n ≥ 1) at the position of the cursor. The position of the cursor does not change. |
Delete(n) | Delete n | Delete the n (n ≥ 1) characters following the cursor. The position of the cursor does not change. |
Get(n) | Get n | Outputs the n (n ≥ 1) characters following the cursor. The position of the cursor does not change. |
| Prev | Prev | Moves the cursor backwards by one character. |
| Next | Next | Moves the cursor forwards by one character. |
For example, an empty text editor when given the operations: Insert(13, "Balanced tree"), Move(2), Delete(5), Next(), Insert(7, "editor"), Move(0), and Get(16), will output "Bad editor tree".
Your task is to:
The first line of input contains an integer t, the number of operations. The following lines contain t operations. To make text from the text editor easier to read, the string following the Insert() operation may contain multiple line breaks. You must ignore them (if this is hard to understand, please refer to the sample input and output below). Other than new line characters, all of the characters in the input will have ASCII values within the range [32, 126], inclusive. There will be no trailing spaces.
You can assume that for each test case:
Each line of the output should contain the text outputted by a single corresponding Get() operation.