#P5217. Advanced Text Editor

    ID: 18453 Type: Default 1000ms 256MiB

Advanced Text Editor

Advanced Text Editor

This problem involves simulating a text editor that supports several operations on a string. Initially, you are given a text S consisting of letters. Each letter in the initial text is assigned an id corresponding to its 1-indexed position. The editor supports the following operations:

  1. I x c: Insert the character c immediately after the x-th letter in the current text. (The text is 1-indexed.)
  2. D x: Delete the x-th letter from the current text.
  3. R x y: Reverse the substring (interval) in the current text from index x to y, inclusive.
  4. P x: For the letter that was originally the x-th letter in the initial text, output its current position in the text. If that letter has been deleted, output 0.
  5. T x: Output the letter at position x in the current text.
  6. Q x y: Output the number of distinct letters that appear in the current text in the interval from x to y (inclusive).

Note that the sequence of operations is performed sequentially, and all positions are 1-indexed. New inserted letters are not tracked for the P operation while the originally provided letters remain associated with their initial indices.

inputFormat

The first line contains the initial text S consisting of only lowercase letters.

The second line contains an integer N, the number of operations.

Each of the following N lines contains one operation in one of the six formats described above.

outputFormat

For each operation of type P, T, or Q, output the corresponding result on a separate line in the order of their appearance in the input.

sample

abc
3
I 2 d
T 3
Q 2 4
d

3

</p>