IITKESO207PA4Q1 - Memory Game 3
After Nitish succesfully completed the challenge given in Memory Game 2, Mahesh figured out that he had used a program written by you. After reading the program, Mahesh thought he will rechallenge Nitish with new set of inputs. Mahesh believes Nitish won't be able to answer the queries in given time. Nitish comes to you again, and asks to improve the program as soon as possible. Rest of the challenge remains same:
Mahesh will ask Nitish to learn words and then perform certain operations on them. The operations are as follows:
1) learn xyz: This command tells Nitish to add the word "xyz" to his dictionary.
2) forget xyz: This command tells Nitish to forget "xyz" from the dictionary. It is guaranteed that word that is asked to be forgotten will be present in the dictionary.
3) findrank xyz: Find the rank of the word "xyz" if the words are arranged in lexicographic order. The lexicographically smallest word is given rank 1.
Important point: A word is simply a string of lowecase characters (a to z). Moreover, it is guaranteed that each word has exactly 10 characters.
Input
The first line contains an integer q denoting the number of queries. q lines follow.
Each of the next line contains one of the 3 different queries
learn xyz - Add xyz to dictionary.
forget xyz - Remove xyz from dictionary.
findrank xyz - Find rank of xyz in the dictionary.
Output
Print nothing in case of learn operation.
For forget operation, print the rank of the word that is removed.
For findrank operation, print the rank of the word.
Constraints
1 <= q <= 5 * 10^5
Example
Input: 10
learn monhdjaecg
learnaelakggcfeaelakggcfe learn mhbmldlcim
learn ahlidlmdlj
learn dlneeklean
forget mhbmldlcim
findrank ahlidlmdlj
findrank monhdjaecg
forget ahlidlmdlj
findrank monhdjaecg
Output:
4
2
4
2
3
Added by: | Programming Club, IITK |
Date: | 2018-03-06 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |