← 返回 amazon 的题目列表Design an index to find sentences by word; support deletion and updates
类型:online_judge
Implement a simplified sentence search system. Each sentence has a unique sentence_id and a text consisting of lowercase letters and spaces (tokens separated by single spaces). Support:
ADD id text: add a new sentence.
DEL id: delete an existing sentence; it must disappear from future queries.
QUERY word: output all current sentence ids containing word, in increasing order; output an empty line if none.
Input
First line: integer q (#operations)
Next q lines: one operation per line
Output
For each QUERY, print one line with matching ids (space-separated, sorted), or an empty line.
Constraints
1 <= q <= 2e5
id is positive; ADD ids are unique; DEL ids always exist
Each sentence has at most 50 words
Example Input:
6
ADD 1 hello world
ADD 2 hello amazon
QUERY hello
DEL 1
QUERY hello
QUERY world
Output:
1 2
2
Example
Input
6
ADD 1 hello world
ADD 2 hello amazon
QUERY hello
DEL 1
QUERY hello
QUERY world
Output
1 2
2