Score : $400$ points
There is a sequence $A = (A_0, A_1, \dots, A_{N - 1})$ with $N = 2^{20}$ terms. Initially, every term is $-1$.
Process $Q$ queries in order. The $i$-th query $(1 \leq i \leq Q)$ is described by an integer $t_i$ such that $t_i = 1$ or $t_i = 2$, and another integer $x_i$, as follows.
Here, for integers $a$ and $b$, $a \bmod b$ denotes the remainder when $a$ is divided by $b$.
Input is given from Standard Input in the following format:
$Q$ $t_1$ $x_1$ $\vdots$ $t_{Q}$ $x_{Q}$
For each query with $t_i = 2$, print the response in one line. It is guaranteed that there is at least one such query.
4 1 1048577 1 1 2 2097153 2 3
1048577 -1
We have $x_1 \bmod N = 1$, so the first query sets $A_1 = 1048577$.
In the second query, initially we have $h = x_2$, for which $A_{h \bmod N} = A_{1} \neq -1$, so we add $1$ to $h$. Now we have $A_{h \bmod N} = A_{2} = -1$, so this query sets $A_2 = 1$.
In the third query, we print $A_{x_3 \bmod N} = A_{1} = 1048577$.
In the fourth query, we print $A_{x_4 \bmod N} = A_{3} = -1$.
Note that, in this problem, $N = 2^{20} = 1048576$ is a constant and not given in input.