import sys
def main():
input = sys.stdin.read().split()
ptr = 0
n = int(input[ptr])
ptr += 1
a = list(map(int, input[ptr:ptr + n]))
ptr += n
q = int(input[ptr])
ptr += 1
queries = []
for _ in range(q):
L = int(input[ptr]) - 1 # converting to 0-based
R = int(input[ptr + 1]) - 1
queries.append((L, R))
ptr += 2
# Process each query by iterating from L to R
res = []
for L, R in queries:
if L >= R:
res.append(0)
continue
count = 0
current_min = a[L]
current_max = a[L]
for i in range(L + 1, R + 1):
if a[i] > current_max:
current_max = a[i]
count += 1
elif a[i] < current_min:
current_min = a[i]
count += 1
res.append(count)
print('\n'.join(map(str, res)))
if __name__ == '__main__':
main()