#P456. 【例83.2】二分查找

【例83.2】二分查找

Description

Binary search on a sorted array is an excellent algorithm: the goal is to find if there exists a[k]=key in the sorted array a[]. If found, return kk; otherwise, return 1-1.

  • If there are multiple a[k]=key, please output the smallest kk.
  • The index kk starts counting from 11.

Input Format

The first line contains an integer NN, representing the length of the array.
The second line contains NN integers (N30000N \le 30000) within the int range, guaranteed to be in ascending order, separated by spaces.
The third line contains an integer TT, representing the number of queries.
The fourth line contains TT integers (T30000T \le 30000) within the int range, representing the keykey values to search for in each query, separated by spaces.

Output Format

A single line containing the results for each query (kk or 1-1), separated by spaces.

Sample

3
-2 -2 1
3
-2 -2 -1
1 1 -1