#P5217. Advanced Text Editor
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:
I x c
: Insert the characterc
immediately after the x-th letter in the current text. (The text is 1-indexed.)D x
: Delete the x-th letter from the current text.R x y
: Reverse the substring (interval) in the current text from index x to y, inclusive.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.T x
: Output the letter at position x in the current text.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>