Shortest Sub-Array

The first line contains two integers $N$ and $Q$ $(3 ≤ N, Q ≤ 5 ×10^5)$ represents the size of array $A$ and number of queries to perform respectively.


This is a companion discussion topic for the original entry at https://toph.co/p/shortest-sub-array