← 返回 anthropic 的题目列表Multi-Level In-Memory Database with TTL and Time Travel
类型:online_judge
Problem: In-Memory Database with TTL and Time Travel
Implement a simplified in-memory database storing string values by (key, field). It must support basic writes, reads, deletes, scans, TTL expiration, and historical point-in-time queries.
Input
The first line contains an integer Q.
Each of the next Q lines is one operation:
SET t key field value: set key.field = value at time t with no expiration.
SET_TTL t key field value ttl: set the value at time t, expiring at t + ttl; valid interval is [t, t + ttl).
GET t key field: return the value valid at time t.
DELETE t key field: delete the field at time t if it is currently valid.
SCAN t key: return all valid fields under key at time t, sorted by field name, formatted as field=value; output null if none exist.
GET_AT t key field at_time: at current time t, query the value at historical time at_time.
Timestamps are non-decreasing in input order.
Output
For every GET, SCAN, and GET_AT, print one line. Print null if no value exists.
Constraints
1 <= Q <= 2 * 10^5
key, field, and value length at most 50
1 <= ttl
timestamps are non-negative integers
Example
Input
7
SET 1 user name alice
GET 2 user name
DELETE 3 user name
GET 4 user name
SET_TTL 5 user name bob 3
GET 7 user name
GET 8 user name
Output
alice
null
bob
null