Smallest Subarray

Limits: 2s, 512 MB

You are given an array A of N integers A1, A2, A3, …, AN . If we select two indices (1 <= i <= j <= N) from the array then there are (j-i+1) subarrays in total which starts in any index between i (inclusive) and j (inclusive) and ends in the last index of the array that is N. Now you are given Q queries. In each query there are 2 integers.


This is a companion discussion topic for the original entry at https://toph.co/p/smallest-subarray