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

Binary search

Time limit: 1000 ms
Memory limit: 256 MB
Given a sorted array $A$ consisting of $n$ distinct integers in ascending order. There are $q$ queries, each query is an integer $x$. Determine the position of this value in the array $A$. ### Input - The first line contains two integers $n$ and $q$. - The second line contains $n$ integers $A_i$ in ascending order. - The next $q$ lines each contain an integer $x$, a query. ### Output - For each query, print the position of the given integer in the array $A$. Ensure that there exists a valid answer. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le A_i, x \le 10^9$. ### Example Input: ``` 5 3 1 4 6 8 10 4 10 1 ``` Output: ``` 2 5 1 ```
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 (1) Solution