This page is still under construction.

Parts of this page are still being built. What you see may change.

Album Manager

Time limit2sMemory limit512 MB

Summary
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 NN of commands to perform, print a string for each command that requires output after the command runs.

  1. 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 SS

      • Create an album named SS in the current album.
      • If an album with the same name already belongs to the current album, do not create the album.
  2. rmalb

    • After the command runs: Print the number of deleted albums and the number of deleted photos, separated by a space.

    • rmalb SS

      • If an album named SS 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.
  3. 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 SS

      • Insert a photo named SS into the current album.
      • If a photo with the same name already belongs to the current album, do not insert the photo.
  4. delete

    • After the command runs: Print the number of deleted photos.

    • delete SS

      • If a photo named SS 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.
  5. ca

    • After the command runs: Print the name of the current album.

    • ca SS

      • Move to the album named SS among the albums belonging to the current album.
      • If no album named SS 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, NN.

The next NN 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 ≤ NN ≤ 105
  • 1 ≤ length of SS ≤ 20
  • SS consists only of lowercase English letters and contains no spaces.

Examples3

  1. Example 1

    Input
    24
    mkalb animal
    mkalb insect
    ca animal
    mkalb sky
    mkalb land
    mkalb ocean
    ca land
    insert elephant
    insert tiger
    insert banana
    delete banana
    ca elephant
    ca ..
    ca ocean
    insert whale
    ca /
    ca insect
    mkalb land
    mkalb sky
    ca ocean
    ca ..
    ca ..
    rmalb -1
    rmalb -1
    
    Expected output
    animal
    land
    1
    land
    animal
    ocean
    album
    insect
    insect
    album
    album
    4 3
    3 0
    
  2. Example 2

    Input
    29
    mkalb domestic
    mkalb ovarseas
    ca domestic
    ca incheon
    mkalb incheon
    ca incheon
    mkalb chinatown
    mkalb wolmido
    ca chinatown
    insert jajangmyeon
    insert champon
    insert friedrice
    insert jajangmyeon
    ca /
    ca domestic
    rmalb incheon
    ca /
    rmalb ovarseas
    mkalb overseas
    ca overseas
    mkalb japanese
    mkalb europe
    rmalb japanese
    ca europe
    rmalb 0
    ca ..
    delete europe
    ca ..
    rmalb 1
    
    Expected output
    domestic
    domestic
    incheon
    chinatown
    duplicated photo name
    album
    domestic
    3 3
    album
    1 0
    overseas
    1 0
    europe
    0 0
    overseas
    0
    album
    2 0
    
  3. Example 3

    Input
    30
    mkalb univ
    mkalb middle
    mkalb elementary
    insert middle
    ca middle
    insert middleschool
    ca ..
    rmalb middle
    ca univ
    mkalb inha
    insert kaist
    insert harvard
    delete harvard
    ca inha
    mkalb inkyungho
    mkalb hightech
    mkalb jungseok
    delete 0
    rmalb 1
    ca jungseok
    ca hightech
    mkalb computer
    mkalb elect
    mkalb machine
    rmalb 1
    rmalb 1
    insert computer
    insert elect
    ca /
    rmalb 0
    
    Expected output
    middle
    album
    1 1
    univ
    1
    inha
    0
    1 0
    inha
    hightech
    1 0
    1 0
    album
    6 3