← 返回 rippling 的题目列表Logger System with Handler Pipeline and Keyword Search
类型:online_judge
Problem: Implement a Logger System with Handler Pipeline and Keyword Search
Design and implement a simplified Logger System.
The system should support the following features:
Add handlers
Handlers form a pipeline in the order they are added.
Every newly written log is processed by all currently registered handlers in order.
Existing logs are not reprocessed when a new handler is added later.
Write logs
Write a raw log message.
The system processes it through all current handlers and stores the processed message.
Each stored log receives an incremental log_id starting from 0.
Search keyword
Given a keyword, return all log_ids whose processed log contains that keyword, in increasing order.
Search rules:
Match complete words only.
A word consists of English letters or digits, i.e. regex [A-Za-z0-9]+.
Search is case-insensitive.
Search should be optimized: do not scan all logs on every search. Maintain an inverted index when logs are added.
This problem supports two handler types:
CAPITAL: converts the whole current log message to uppercase.
ADD suffix: appends suffix to the end of the current log message.
Input Format
The first line contains an integer Q, the number of operations.
Each of the next Q lines is one of the following operations:
ADD_HANDLER CAPITAL
ADD_HANDLER ADD <suffix>
LOG <message>
SEARCH <keyword>
Notes:
<message> and <suffix> may contain any characters except newline.
<keyword> is a word containing only English letters or digits.
Output Format
For each SEARCH operation:
If matching logs exist, print all matching log_ids separated by a single space.
Otherwise, print EMPTY.
Constraints
1 <= Q <= 2 * 10^5
Length of each message/suffix <= 10^3
Total number of characters after all LOG operations <= 10^6
Expected complexity:
LOG should be close to the length of the current processed message.
SEARCH should be close to the number of returned results, not the number of all logs.
Example
Input:
5
LOG hello world
SEARCH hello
ADD_HANDLER CAPITAL
LOG hello world
SEARCH hello
Output:
0
0 1
Example
Input
5
LOG hello world
SEARCH hello
ADD_HANDLER CAPITAL
LOG hello world
SEARCH hello
Output
0
0 1