RMQSQ - Range Minimum Query
You are given a list of N numbers and Q queries. Each query is specified by two numbers i and j; the answer to each query is the minimum number between the range [i, j] (inclusive).
Note: the query ranges are specified using 0-based indexing.
The first line contains N, the number of integers in our list (N <= 100,000). The next line holds N numbers that are guaranteed to fit inside an integer. Following the list is a number Q (Q <= 10,000). The next Q lines each contain two numbers i and j which specify a query you must answer (0 <= i, j <= N-1).
For each query, output the answer to that query on its own line in the order the queries were made.
1 4 1
AC in one go took 0.59s , <JAVA>[*_*] :)
koi btayega ye code kyun wrong answer de rha hai ?
this question can be done in 3 ways(i recommend trying all)
Dynamic programming approach with N^2 preprocessing using 2D array won't work
solved using modified BIT
Square root decomposition also works.
Segment tree faster than sparse table . Compare O(NlogN+Q) with O(N+QlogN).
using array instead of a vector resulted in AC from TLE !!Last edit: 2016-07-05 08:46:34
Sparse Table ... :-)