k-th occurence - MarisaOJ: Marisa Online Judge

k-th occurence

Time limit: 1000 ms
Memory limit: 256 MB
For an array $A$ consisting of $n$ elements, given $q$ queries of the form $x, k$, find the index of the $k$-th occurrence of the element with value $x$, counting from index $1$. ### Input - The first line consists of two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines, each containing two integers $x, k$, representing a query. ### Output - For each query, output an integer as the answer. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le A_i, k \le 10^9$. - The queries guarantee the existence of an answer. ### Sample test Input ``` 8 5 1 1 3 4 2 1 4 2 1 3 1 2 1 1 4 2 2 1 ``` Output: ``` 6 2 1 7 5 ```