← 返回 meta 的题目列表Optimize Word Container / String Matching Queries (ParanoidEcho)
类型:online_judge
Coding: Optimize a Word Container for Prefix Queries (ParanoidEcho)
Implement a string container supporting efficient queries.
Operations
ADD word: add word into the container (deduplicate is fine).
QUERY s: output YES if there exists a stored word w such that w is a prefix of s, otherwise output NO.
You should implement an approach faster than the brute force solution that scans all stored words for each query.
Input (stdin)
First line: integer q
Next q lines: either
ADD <word>
QUERY <s>
Output (stdout)
For each QUERY, print YES or NO.
Constraints
1 <= q <= 2e5
Strings contain only lowercase letters a-z
Total length of all strings <= 2e5
Test cases
Example
Input
6
ADD a
ADD ab
QUERY abc
QUERY b
ADD bc
QUERY bca
Output
YES
NO
YES