#P1383. 高级打字机

    ID: 378 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>倍增福建省历届夏令营主席树可持久化

高级打字机

Description

Sanae has bought the latest advanced typewriter. As you would expect, the latest model has a new feature: it supports undo.

Please design a program for this advanced typewriter that supports the following 33 types of operations:

  1. T x: Type operation, which appends a lowercase letter xx to the end of the text.
  2. U x: Undo operation, which undoes the last xx modification operations.
  3. Q x: Query operation, which asks for and outputs the xx-th letter of the current text. Note that the Query operation does not count as a modification operation.

Initially, the text can be regarded as an empty string.

Input Format

Line 11: an integer nn, the number of operations.

The next nn lines each contain one command. It is guaranteed that the input commands are valid.

Output Format

Output one letter per line, which is the answer to each Query operation.

7
T a
T b
T c
Q 2
U 2
T c
Q 2

b
c

Hint

For the first 20%20\% of the testdata, n200n \le 200.

For the first 50%50\% of the testdata, it is guaranteed that an Undo operation will not undo an Undo operation.

For 100%100\% of the testdata, n105n \le 10^5.

Translated by ChatGPT 5