AGPC01F – Can you search? Solution

SPOJ Solution

AGPC01F Statement

Shimlin loves to play with array. One day she was playing a game of finding the smallest number in an array but soon she got bored as the game was too easy for her. She asked her ghost friend to make the game more interesting. After thinking for a while the ghost came up with an idea. The ghost will give her some queries. In each query the ghost will tell her a number bi (less than the given array size) and Shimlin will have to answer the smallest number among first bi elements of the given array.

The ghost gave you the responsibility to find the correct answer of each query so that he can match the answer with Shimlin’s answer.


Input starts with T(1<=T<=100), denoting the number of test case.

Each of the test case contains 3 line.

In the first line there are two positive integer numbers n and q (1 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5) — size of the array and number of queries.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 10^5) — elements of the array.

The third line contains q integers b1, b2, …, bq (1 ≤ bi ≤ n) — range of query.


For each query print one integer in a line— the minimum number in that range.

AGPC01F  Solution

You also like to see:


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.