#P3156. Classroom Entry Query

    ID: 16413 Type: Default 1000ms 256MiB

Classroom Entry Query

Classroom Entry Query

You are given \(n\) students entering a classroom sequentially. Each student has a unique student ID in the range \(1\) to \(10^9\). The order of the student IDs is provided as they enter the classroom.

After all students have entered, you are given \(q\) queries. The \(i\)-th query asks for the student ID of the \(i\)-th student who entered the classroom (with \(i=1\) corresponding to the first student).

Constraints:

  • \(1 \leq n \leq 2 \times 10^6\)
  • \(1 \leq q \leq 10^5\)
  • Each student ID is an integer in the range \(1\) to \(10^9\)

inputFormat

The first line contains two integers \(n\) and \(q\), representing the number of students and the number of queries respectively.

The second line contains \(n\) space-separated integers, where the \(j\)-th integer represents the student ID of the \(j\)-th student entering the classroom.

The following \(q\) lines each contain one integer \(i\), indicating a query for the student ID of the \(i\)-th student who entered the classroom.

outputFormat

For each query, output the student ID of the corresponding student on a separate line.

sample

5 3
10 20 30 40 50
1
3
5
10

30 50

</p>