PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000220. Kho dữ liệu theo thời gian (Time Based Key-Value Store)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 kk at time tt considers only earlier writes to that key whose timestamps are at most tt. Return the value of the latest eligible write, or - to represent an empty result.

Input

The first line contains qq. Each of the next qq lines has one of two forms:

  • 1 k v t: store value vv for key kk at time tt.
  • 2 k t: look up key kk at time tt.

Output

Print one line per type-2 operation, containing the value found or -. Type 1 produces no output.

Subtasks

  • Subtask 1 (20 points): 1≤q≤1001\le q\le100; 1≤∣k∣,∣v∣≤1001\le |k|,|v|\le100 when present; strings contain only lowercase English letters and digits; 1≤t≤1071\le t\le10^7; write timestamps strictly increase; only the specified two operation types occur.
  • Subtask 2 (30 points): 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤∣k∣,∣v∣≤1001\le |k|,|v|\le100 when present; strings contain only lowercase English letters and digits; 1≤t≤1071\le t\le10^7; 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): 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤∣k∣,∣v∣≤1001\le |k|,|v|\le100 when present; strings contain only lowercase English letters and digits; 1≤t≤1071\le t\le10^7; 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 -.