#P5335. [THUSC 2016] 补退选
[THUSC 2016] 补退选
Description
X is a teacher at University T. Every year, he teaches many students basic C++ knowledge. At University T, before the start of each semester, every student needs to choose courses. Each course selection process has three stages: pre-selection, main selection, and add/drop; among them, the “add/drop” stage is the busiest.
During the add/drop stage, students can either add a course or drop a course. For Teacher X, the following two types of events may happen during the add/drop stage:
- A student with name adds his course (the name will appear in X’s list of enrolled students).
- A student with name drops his course (the name will be removed from X’s list of enrolled students).
At the same time, Teacher X cares a lot about which students have enrolled in his course, so he will query the enrolled-student list from time to time. For each query, he asks: after which event, as early as possible, does the number of students whose names have prefix become greater than .
Teacher X thinks you are talented, so he wants to test you with this problem. You are not afraid, so you bravely take on the task.
Note 1: Student names may be the same. If there are students with the same name who have all enrolled in Teacher X’s course, then their name will appear times in Teacher X’s list.
Note 2: Only students who have already enrolled can drop the course. If a student with name drops the course, then before dropping, Teacher X’s list must contain that name.
Note 3: Adding, dropping, and querying are all defined as “events”, and event indices start from .
Input Format
The first line contains a positive integer , indicating that a total of events occur.
In the next lines, each line describes an event. The first integer in each line indicates the event type:
- If , it is an add-course event. Next comes a string , meaning that a student with name adds Teacher X’s course.
- If , it is a drop-course event. Next comes a string , meaning that a student with name drops Teacher X’s course.
- If , it is a query event. Next comes a string and three non-negative integers , meaning that Teacher X wants to know after which event, as early as possible, the number of students whose names have prefix becomes greater than . denotes the absolute value of the answer to the previous query event. If this is the first query, then . If this value is never exceeded at any time, then the answer is .
Note: All strings in the input contain only lowercase letters.
Output Format
For each query event, output one line containing the answer to that query.
8
1 jead
1 dec
3 de 0 0 10
1 dec
3 de 0 1 10
2 dec
3 de 0 1 10
3 de 0 2 10
2
4
4
-1
Hint
. All strings in the input contain only the first lowercase letters.
Translated by ChatGPT 5
京公网安备 11011102002149号