For a segment [l, r], you need to know whether there are (r — l + 1) distinct segments whose length is 1, and they all fall within [l, r]. While taking the input, whenever l = r, update prefix[l] = 1. After taking input, iterate over the whole prefix array from left to right in order obtain the cumulative sum. Then, if prefix[r] — prefix[l — 1] == r — l + 1 for l not equal to r, then answer for that segment is 0. Otherwise, 1.
For a segment [l, r], you need to know whether there are (r — l + 1) distinct segments whose length is 1, and they all fall within [l, r]. While taking the input, whenever l = r, update prefix[l] = 1. After taking input, iterate over the whole prefix array from left to right in order obtain the cumulative sum. Then, if prefix[r] — prefix[l — 1] == r — l + 1 for l not equal to r, then answer for that segment is 0. Otherwise, 1.