Counting suffixes P88868


Statement
 

pdf   zip

Please implement a data structure DD to efficiently support four operations:

  • I ss: Inserts the string ss into DD. No changes are made if ss is already in DD.

  • E ss: Erases the string ss from DD. No changes are made if ss is not in DD.

  • C ss: Counts the number of strings in DD that end with the suffix ss.

  • R: Resets DD, that is, removes all strings from DD.

Input

Input consists of several operations over an initially empty DD. Assume that each ss is made up of between 1 and 100 lowercase letters. At no moment the sum of the sizes of the strings stored in DD will be larger than 10610^6.

Output

Print the result of each C ss operation, and three dashes for each R operation.

Public test cases
  • Input

    E a
    I abba
    C a
    I cba
    C cba
    C abba
    C a
    C ba
    I abba
    C ba
    E cba
    C cba
    C a
    E ba
    C ba
    R
    C ba
    I eggs
    I zzeggs
    C eggs
    E eggs
    C eggs
    

    Output

    1
    1
    1
    2
    2
    2
    0
    1
    1
    ---
    0
    2
    1
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++