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 0based indexing.
Input
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 <= N1).
Output
For each query, output the answer to that query on its own line in the order the queries were made.
Example
Input: 3
1 4 1
2
1 1
1 2
Output: 4
1
hide comments
shashank joshi:
20170526 11:21:17
koi btayega ye code kyun wrong answer de rha hai ?


sonu1801:
20170525 15:52:41
this question can be done in 3 ways(i recommend trying all)


avidcoder:
20170411 08:04:09
Dynamic programming approach with N^2 preprocessing using 2D array won't work 

Randomize:
20161115 11:14:47
solved using modified BIT 

thomasdo:
20160922 12:35:32
too hard!!!


rohithr31:
20160917 08:44:08
Square root decomposition also works. 

razor123:
20160912 14:11:09
Segment tree faster than sparse table . Compare O(NlogN+Q) with O(N+QlogN). 

gabbar:
20160702 23:14:45
using array instead of a vector resulted in AC from TLE !! Last edit: 20160705 08:46:34 

kartikay singh:
20160627 13:30:07
Sparse Table ... :) 

abhilc:
20160617 21:37:41
Why not sparse tables? AC! 
Added by:  Joshua Kirstein 
Date:  20141018 
Time limit:  3s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 