← 返回 google 的题目列表Streaming Latest-Per-Message Log Processor
类型:online_judge
Implement a streaming log processor. Logs arrive one at a time through add_log(timestamp, message). For each message, only the entry with the greatest timestamp is valid.
The processor must support:
add_log(timestamp, message): add a log entry. It may invalidate a previously valid entry for that message.
get_next(): return the valid, not-yet-returned entry with the smallest timestamp as (timestamp, message). Return None if no such entry exists.
Once get_next() returns an entry, that entry must not be returned again. Lazy deletion is allowed: old entries may remain in a heap, but they must be recognized and skipped when popped.
For equal timestamps, get_next() must return the lexicographically smaller message first.
Operation example
add_log(5, "a")
add_log(2, "b")
add_log(8, "a")
get_next() -> (2, "b")
get_next() -> (8, "a")
get_next() -> None
Constraints
At most 2 * 10^5 operations.
Timestamps are signed 64-bit integers.
Example
Input
6
add 5 a
add 2 b
add 8 a
get
get
get
Output
2 b
8 a
None