report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Binary search 2 - MarisaOJ: Marisa Online Judge

Binary search 2

Time limit: 1000 ms
Memory limit: 256 MB
You are given: - An integer non-decreasing array $A$ of $n$ integers. - $q$ queries, each is an integer $x$, find the smallest $i$ that $A_i = x$. ### Input - The first line contains 2 integer $n, q$. - The second line contains $n$ space-separated integers $A_i$. - The next $q$ lines, each contains an single integer $x$, a query. ### Output - Print $q$ lines, $i^{th}$ line is the answer to query $i$. Print `-1` if $x$ cannot be found. ### Constraints - $1 \le n, q \le 10^{5}$. - $1 \le A_i \le 10^9$. ### Example Input: ``` 5 3 1 2 3 3 9 1 9 3 ``` Output: ``` 1 5 3 ```
Introduction to Binary Search
Binary search
Binary search 2
Binary search 3
Large subarray
Count query
Counting pairs
The k-th candy
Triangle edges
Hamming number
Consecutive integers
Gnimmah distance
Subarray
Topic
Binary search
Rating 800
Solution (0) Solution