#P4567. Simple and Efficient Text Editor

    ID: 17813 Type: Default 1000ms 256MiB

Simple and Efficient Text Editor

Simple and Efficient Text Editor

This problem requires you to implement a simple text editor that supports a limited set of operations. The editor maintains a text (a sequence of characters whose ASCII codes are in the interval $[32,126]$) and a cursor that indicates a position within the text. Initially, the editor is empty and the cursor is at the beginning (i.e. before any characters).

The editor supports the following operations:

  • Move k: Move the cursor to the position immediately after the $k$-th character. Note that if $k=0$, the cursor is moved to before the first character.
  • Insert n: Insert a string $S$ of length $n$ after the cursor. The string $S$ is provided on the next line. The cursor remains unchanged after insertion.
  • Delete n: Delete the next $n$ characters after the cursor. The cursor remains unchanged.
  • Rotate n: Reverse the order of the next $n$ characters after the cursor. The cursor remains unchanged. Formally, if the substring after the cursor is $s_1s_2\ldots s_n$, after the operation it becomes $s_n s_{n-1}\ldots s_1$.
  • Get: Output the character immediately after the cursor. The cursor remains unchanged.
  • Prev: Move the cursor one position to the left (if possible).
  • Next: Move the cursor one position to the right (if possible).

Additional Definitions:

  • Text: A sequence of zero or more visible characters (or space) with ASCII codes in the interval $[32,126]$.
  • Cursor: A marker that can be placed before the first character, after the last character, or between two adjacent characters in the text.

Your task is to simulate the editor. Start with an empty text editor and execute the operations sequentially as provided in the input. For every Get operation, output the corresponding character.

inputFormat

The first line contains an integer $Q$, the number of operations. The following lines specify the operations. Each operation is one of the following:

  • Move k
  • Insert n — followed by a line with a string $S$ of length $n$
  • Delete n
  • Rotate n
  • Get
  • Prev
  • Next

You can assume that all operations are valid.

outputFormat

For each Get operation, output the corresponding character on a separate line.

sample

7
Insert 5
Hello
Get
Move 0
Insert 1
_
Get
H

_

</p>