Query on string - MarisaOJ: Marisa Online Judge

Query on string

Time limit: 3000 ms
Memory limit: 256 MB
You are given a set $S$ of $0$ string. There are $q$ queries of the following types: - Add a string to $S$. - Determine if there exists a group of $k$ strings having common suffix of length $l$. - Remove the string added in the $i^{th}$ query, it is guaranteed that the string exists in $S$. ### Input - The first line contains an integer $q$. - The next $q$ lines, each line follow the form: + `1 s`: Add string $s$ to $S$. + `2 k l`: Determine if there exists a group of $k$ strings having common suffix of length $l$. + `3 i`: Remove the string added in the $i^{th}$ operation. ### Output - Print the answer for the query of type $2$. Print `YES` if it exists, otherwise print `NO`. ### Constraints - $1 \le q \le 10^5$. - $1 \le k, l \le 10^6$. - $1 \le i \le q$. - The sum of string length does not exceed $10^6$. - $S_i$ contain only lowercase letters. ### Example Input: ``` 9 1 aba 1 accba 2 2 2 2 2 3 1 aaaa 1 ababa 2 3 2 3 1 2 3 2 ``` Output: ``` YES NO YES NO ```