I need help with this problem!!!

Revision en1, by desperateboy12344, 2024-09-06 16:03:41

Hi guys, as the title stated, I really need your help with this problem

You have a set. Initially the set is empty. Given Q queries, there are two types of queries:

1 s : s is a string, add s to the set. If the set already contains s, do nothing

2 S : For all string k that belong to the set, calculate the sum of D(k) * length(k), D(k) is the number of occurrences of k in S as a substring (example, aa is a substring of aabc, ac is not a substring of aabc) and length(k) is length of k

Example :

Q = 5

1 aa

2 aa

1 aa

1 ab

2 ababaa

-> output : 2 , 6

Note: After the first query, the set is {aa}, hence the answer for the second query is 2

After the fourth query, the set is {aa,ab} -> ababaa = 6 because ab appears twice, aa appear once : 2*2 + 2*1 = 6

Tags string

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English desperateboy12344 2024-09-06 16:04:47 91
en1 English desperateboy12344 2024-09-06 16:03:41 826 Initial revision (published)