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

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

2 lộ trình

Dò tuyến tính (Linear Probing)

Linear Probing

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An array AA has N=220N=2^{20} entries indexed 00 through N−1N-1, all initially equal to −1-1. Process QQ queries in order. Query 1 x scans cyclically forward starting at index x mod Nx\bmod N until it finds an entry equal to −1-1, then stores xx there. Query 2 x outputs the current value of Ax mod NA_{x\bmod N}. An empty position is guaranteed for every insertion.

Input

The first line contains QQ. Each following line contains ti,xit_i,x_i.

Output

For each query of type 2, print one integer on its own line.

Subtasks

  • Subtask 1 (20 points): N=220N=2^{20}, 2≤Q≤322\le Q\le 32, 0≤xi≤10180\le x_i\le 10^{18}, ti∈{1,2}t_i\in\{1,2\}; at least one type 22 query.
  • Subtask 2 (30 points): N=220N=2^{20}, 2≤Q≤3502\le Q\le 350, 0≤xi≤10180\le x_i\le 10^{18}, ti∈{1,2}t_i\in\{1,2\}; at least one type 22 query.
  • Subtask 3 (50 points): N=220N=2^{20}, 1≤Q≤2⋅1051\le Q\le 2\cdot10^5, 0≤xi≤10180\le x_i\le 10^{18}, ti∈{1,2}t_i\in\{1,2\}; at least one type 22 query.

Examples

Input

4
1 1048577
1 1
2 2097153
2 3

Output

1048577
-1

Explanation

The first insertion occupies index 11; the next insertion skips to index 22. The two reads return 10485771048577 and −1-1.