PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000093. Dò tuyến tính (Linear Probing)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dò tuyến tính (Linear Probing)
Linear Probing
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An array has entries indexed through , all initially equal to . Process queries in order. Query 1 x scans cyclically forward starting at index until it finds an entry equal to , then stores there. Query 2 x outputs the current value of . An empty position is guaranteed for every insertion.
Input
The first line contains . Each following line contains .
Output
For each query of type 2, print one integer on its own line.
Subtasks
- Subtask 1 (20 points): , , , ; at least one type query.
- Subtask 2 (30 points): , , , ; at least one type query.
- Subtask 3 (50 points): , , , ; at least one type query.
Examples
Input
4
1 1048577
1 1
2 2097153
2 3
Output
1048577
-1
Explanation
The first insertion occupies index ; the next insertion skips to index . The two reads return and .