#P5217. 贫穷

贫穷

Description

This text editor supports the following operations:

  • I x c\texttt{I x c}: Insert a cc after the xx-th letter.
  • D x\texttt{D x}: Delete the xx-th letter.
  • R x y\texttt{R x y}: Reverse the interval [x,y][x,y] in the current text.
  • P x\texttt{P x}: Output the position of the xx-th letter in the initial text within the current text. In particular, if it does not exist, output 00.
  • T x\texttt{T x}: Output the xx-th letter in the current text.
  • Q x y\texttt{Q x y}: Output the number of different kinds of letters that have appeared in interval [x,y][x,y] of the current text.

Input Format

The first line contains two integers n,mn,m, representing the length of the initial text and the number of operations.
The second line contains a string of length nn, representing the initial text.
The next mm lines each describe one operation.

Output Format

For every operation that requires output, print the result.

12 6
kimiwakawaii
R 2 4
P 4
D 1
I 0 w
T 3
Q 3 10
2
m
5

Hint

Constraints:

For 20%20\% of the testdata, n100n \le 100.
For 50%50\% of the testdata, n10000n \le 10000.
For 100%100\% of the testdata, 1n,m1051 \le n,m \le 10^5, and the text contains only lowercase letters.

Sample Explanation:

  1. The text does not change, but the positions of the 22-nd and 44-th letters in the initial text are swapped.
  2. The current 22-nd letter is the 44-th letter of the initial text.
  3. The text becomes imiwakawaii\texttt{imiwakawaii}.
  4. The text becomes wimiwakawaii\texttt{wimiwakawaii}.
  5. This letter is m\texttt{m}.
  6. This segment is miwakawa\texttt{miwakawa}, and the set of character kinds it contains is $\{\texttt{a},\texttt{i},\texttt{k},\texttt{m},\texttt{w}\}$, so the number of elements is 55.

Translated by ChatGPT 5