Problem 694
Time Based Key-Value Store
Medium · 20 pts · Design, Hash Table, Binary Search
Problem
Build a key-value store that keeps every version of each key. 'set key value t' stores value for key at timestamp t; the timestamps of all set operations strictly increase. 'get key t' prints the value set for key at the largest timestamp that is at most t, or NONE if the key has no value at or before t. Keep a list of (timestamp, value) pairs per key; it is already sorted, so each get is one binary search.
Input
The first line contains Q. Each of the next Q lines contains one operation. Keys and values are lowercase words. There is at least one get.
Output
Print the result of every get, one per line.
Constraints
1 <= Q <= 200000; 1 <= t <= 10^7; set timestamps strictly increase
Example input
6 set foo bar 1 get foo 1 get foo 3 set foo bar2 4 get foo 4 get foo 5
Example output
bar bar bar2 bar2
Explanation
After set foo bar 1, get foo 1 and get foo 3 both print bar. After set foo bar2 4, get foo 4 and get foo 5 print bar2, while a get before time 1 would print NONE.