Minimum query - MarisaOJ: Marisa Online Judge

Minimum query

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ consisting of $n$ integers and $q$ queries, each represented as a tuple $(l, r)$. The task is to determine the index of the smallest value within the subarray $A_l, A_{l+1}, \ldots, A_r$ for each query. ### Input - The first line contains two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines, each line contains two integers $l, r$, a query. ### Output - Print the answer for each query. If there multiple indices with the same minimum value, print the smallest one. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le A_i \le 10^9$. - $1 \le l \le r \le n$. ### Example Input: ``` 4 2 1 4 3 1 1 4 2 3 ``` Output: ``` 1 3 ```
Topic
Data structure
Rating 1300
Solution (0) Solution