luogu#P8045. [COCI 2015/2016 #4] HAN
[COCI 2015/2016 #4] HAN
Background
Han did not want to study alone, so he invited his friend Dominik over. After they studied together for an evening, Dominik went home. To his surprise, a police officer stopped him and believed that he was drunk. As everyone knows, in this situation, by solving a series of carefully designed tasks to test a person’s cognitive ability, one can prove whether they are sober. If we can trust Dominik, the conversation would go like this—
Police officer: Let’s start with an easy question... What is the complexity of bubble sort?
Dominik: Too easy, .
Police officer: Very good, next question. Please recite the English alphabet backwards.
Dominik: Too boring, .
Police officer: You clearly memorized that, it does not count. Let me test you with another question. Imagine that all letters from to are placed clockwise in order on a circle. Initially, you start from the letter and read letters clockwise. After you finish reading each letter, I can tell you to read in the opposite direction, or I can ask how many times you have read a certain letter so far. Ready? Start!
Dominik: Uh... , , ...
The police officer’s last question obviously stumped Dominik. Now, please help Dominik answer these questions.
Problem Description
Specifically, the police officer will give commands. Each command is one of the following two types:
- : After Dominik says the -th letter, he must start reading letters in the opposite direction to the current one.
- : Dominik needs to answer how many times the letter appears among the first letters he has said.
For each command, output the answer.
Input Format
The first line contains an integer , which is the number of commands given by the police officer.
Then follow lines describing the commands. Each line first contains a string and an integer . If is , then after the integer you also need to input a character .
The testdata guarantees that for all commands, is strictly increasing. Formally, , .
Output Format
For each command, output one line with an integer, which is the number of times the character appears among the first letters Dominik has said.
5
UPIT 1 b
UPIT 3 b
SMJER 4
UPIT 7 a
UPIT 10 z
0
1
2
1
5
SMJER 1
SMJER 2
SMJER 3
UPIT 5 a
UPIT 7 w
2
1
4
UPIT 100 a
UPIT 200 c
UPIT 300 a
UPIT 400 b
4
8
12
16
Hint
[Sample 1 Explanation]
The first letters Dominik says, in order, are: , , , , , , , , , .
[Sample 2 Explanation]
The first letters Dominik says, in order, are: , , , , , , .
[Constraints]
For of the testdata, .
For of the testdata, .
For all testdata, , , and contains only lowercase letters.
[Source]
This problem is from COCI 2015-2016 CONTEST 4 T2 HAN, and according to the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5