Untitled
unknown
plain_text
a year ago
944 B
2
Indexable
Never
# import sys # import os # import io # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # output = sys.stdout.buffer.write # def print(*values, sep=" ", end="\n"): # output(sep.join(str(value) for value in values).encode()) # output(end.encode()) n, q = map(int, input().split()) a = [int(i) for i in input().split()] check = [0] * n l = 0 for i in range(n): if i == n - 1 or a[i] < a[i + 1]: check[i] = 1 check[l] = 1 l = i + 1 # print(check) ps = [0] * n ps[0] = check[0] for i in range(1, n): ps[i] = ps[i - 1] + check[i] # print(check) for _ in range(q): l, r = map(int, input().split()) if l == r: print(1) else: ans = 0 if check[l - 1] == 0: ans += 1 if check[r - 1] == 0: ans += 1 ans += ps[r - 1] if l - 2 >= 0: ans -= ps[l - 2] print(ans)