Distinct Substring Queries 2
Time limit1sMemory limit512 MB
Process a stream of append-character and count-distinct-substrings queries on a growing string, answering each count query online.
- Level
Hard8 of 10
- Topics
- String, String matching, Sorting, Implementation
- Solved
- No attempts yet
Problem
There is an empty string . Write a program that processes the following two kinds of queries in order.
c: append the charactercto the end of . Herecis a lowercase English letter.?: print the number of distinct substrings of .
Input
The first line gives a string . is the concatenation of the queries in the order they are performed. consists only of lowercase English letters and ?, and its length does not exceed . contains at least one ?.
Output
For each ?, print the number of distinct substrings of on its own line.