Album Manager
Time limit2sMemory limit512 MB
Simulate an album tree with add, delete, insert, and navigation commands, counting deleted albums and photos under each subtree.
- Level
Medium6 of 10
- Topics
- Tree, Hash map, Simulation, Implementation
- Solved
- No attempts yet
Problem
Jihye wrote an album management program to organize the photos on her computer. The program always has an "album" folder, and the "album" folder can never be deleted. When the program starts, it begins at the "album" folder, and commands let her delete and add albums, delete and add photos, and move the current album. The program consists of the following commands. Given the number of commands to perform, print a string for each command that requires output after the command runs.
-
mkalb
-
After the command runs: If an album with the same name already belongs to the current album and the album was not created, print "duplicated album name". Otherwise print nothing.
-
mkalb
- Create an album named in the current album.
- If an album with the same name already belongs to the current album, do not create the album.
-
-
rmalb
-
After the command runs: Print the number of deleted albums and the number of deleted photos, separated by a space.
-
rmalb
- If an album named belongs to the current album, delete that album.
- All albums and photos belonging to the deleted album are also deleted.
-
rmalb -1
- If the current album has any albums, delete the album whose name comes first in lexicographic order.
- All albums and photos belonging to the deleted album are also deleted.
-
rmalb 0
- Delete every album belonging to the current album.
- All albums and photos belonging to the deleted albums are also deleted.
-
rmalb 1
- If the current album has any albums, delete the album whose name comes last in lexicographic order.
- All albums and photos belonging to the deleted album are also deleted.
-
-
insert
-
After the command runs: If a photo with the same name already belongs to the current album and the photo was not inserted, print "duplicated photo name". Otherwise print nothing.
-
insert
- Insert a photo named into the current album.
- If a photo with the same name already belongs to the current album, do not insert the photo.
-
-
delete
-
After the command runs: Print the number of deleted photos.
-
delete
- If a photo named belongs to the current album, delete that photo.
-
delete -1
- If the current album has any photos, delete the photo whose name comes first in lexicographic order.
-
delete 0
- Delete every photo belonging to the current album.
-
delete 1
- If the current album has any photos, delete the photo whose name comes last in lexicographic order.
-
-
ca
-
After the command runs: Print the name of the current album.
-
ca
- Move to the album named among the albums belonging to the current album.
- If no album named belongs to the current album, stay in the current album.
-
ca ..
- Move to the parent album of the current album.
- If the current album is the top-level "album" folder, stay in the current album.
-
ca /
- Move to the top-level "album" folder.
-
"A belongs to B" means that B is a direct child of A. If A belongs to B and B belongs to C, then A does not belong to C.
Input
The first line gives the number of commands to perform, .
The next lines give the commands of the album management program.
Output
Print the appropriate strings according to the descriptions of the album management program commands in the problem statement.
Constraints
- 1 ≤ ≤ 105
- 1 ≤ length of ≤ 20
- consists only of lowercase English letters and contains no spaces.