#BS0000220. Kho dữ liệu theo thời gian (Time Based Key-Value Store)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kho dữ liệu theo thời gian (Time Based Key-Value Store)
Time Based Key-Value Store
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An initially empty store records keys, values and write timestamps. A key can receive multiple values. Write timestamps strictly increase globally, across all keys.
A lookup for key at time considers only earlier writes to that key whose timestamps are at most . Return the value of the latest eligible write, or - to represent an empty result.
Input
The first line contains . Each of the next lines has one of two forms:
1 k v t: store value for key at time .2 k t: look up key at time .
Output
Print one line per type-2 operation, containing the value found or -. Type 1 produces no output.
Subtasks
- Subtask 1 (20 points): ; when present; strings contain only lowercase English letters and digits; ; write timestamps strictly increase; only the specified two operation types occur.
- Subtask 2 (30 points): ; when present; strings contain only lowercase English letters and digits; ; write timestamps strictly increase; each lookup timestamp is at least the most recent preceding write timestamp, if a write exists; only the specified two operation types occur.
- Subtask 3 (50 points): ; when present; strings contain only lowercase English letters and digits; ; write timestamps strictly increase; only the specified two operation types occur.
Examples
Input
7
1 foo bar 1
2 foo 1
2 foo 3
1 foo bar2 4
2 foo 4
2 foo 2
2 z 9
Output
bar
bar
bar2
bar
-
Explanation
The first two lookups select the write at time 1. After bar2 is written at time 4, the lookup at 4 returns bar2, but the lookup at 2 returns bar. Key z has no writes, so the final result is -.