← 返回 airbnb 的题目列表Parcel Tracking System — Event Recording and Querying
类型:online_judge
Problem: Parcel Tracking System (Level 1)
Implement a simplified parcel tracking system. Each parcel is identified by a unique string parcelId. A parcel may have multiple event types, each identified by a string eventType. The system maintains a running count for every (parcelId, eventType) pair.
Implement ParcelTrackingSystem with the following methods:
record_event(parcel_id: str, event_type: str, count: int) -> int
Record an event of type event_type for parcel parcel_id and increase its running count by count.
If the parcel or event type does not exist yet, create it with running count count.
Return the updated running count.
get_event_count(parcel_id: str, event_type: str) -> int | None
Return the current running count for event_type on parcel parcel_id.
Return None if either the parcel or event type does not exist.
remove_event(parcel_id: str, event_type: str) -> bool
Remove the complete record for event_type from parcel parcel_id.
Return True if a record was removed; otherwise return False.
If removing the event leaves the parcel with no event types, remove the parcel as well.
Example
record_event("A", "B", 5) -> 5
record_event("A", "B", 6) -> 11
get_event_count("A", "B") -> 11
get_event_count("A", "C") -> None
remove_event("A", "B") -> True
remove_event("A", "B") -> False
CLI Input Format
The first line contains an integer q, followed by q operations:
RECORD <parcelId> <eventType> <count>
GET <parcelId> <eventType>
REMOVE <parcelId> <eventType>
Print the return value of every operation. Print null for None, and lowercase true / false for Boolean values.
Constraints
parcelId and eventType are whitespace-free strings.
count is an integer.
The original prompt does not state a bound for q; target expected O(1) time per operation.
The screenshot lists a 40-second execution limit and a 4-GB memory limit.
Example
Input
6
RECORD A B 5
RECORD A B 6
GET A B
GET A C
REMOVE A B
REMOVE A B
Output
5
11
11
null
true
false