BSEARCH1 - Binary search
You are given a sorted array of numbers, and followed by number of queries, for each query if the queried number is present in the array print its position, else print -1.
First line contains N Q, number of elements in the array and number of queries to follow,
Second line contains N numbers, elements of the array, each number will be -10^9<= ai <= 10^9, 0 < N <= 10^5, 0 < Q <= 5*10^5
For each element in the query, print the elements 0 based location of its first occurence, if present, otherwise print -1.
Input: 5 4
2 4 7 7 9
2 Output: 2
this website does'nt accepts cin & cout.
read the comments till end.
hint : lower_bound gives the iterator to the first element in the array that is equal or GREATER than the number being searched . ( so you could get a valid index in return even though the element would not be present in the array, so you need to check if the iterator points to the number actually being searched to validate the answer )
Go to hell this stupid TLE thing, just because I didn't write scanf and printf.
Simple binary search and arrays worked for me along with scanf/printf
it is giving run time error..how can i remove it?
Remember: it's a SORTED vector as input.
python is giving TLE :(
can use map..AC in 0.29 seconds