Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get(a, b):
- i = lg[b - a + 1]
- return min(st[i][a], st[i][b -(2**i) + 1])
- n = int(input())
- a = list(map(int, input().split()))
- lg = [0] * (n + 1)
- for i in range(2, n+1):
- lg[i] = lg[i//2] + 1
- st = [[0] * n for i in range(lg[n] + 1)]
- st[0] = a[:]
- for i in range(1, lg[n]+1):
- x = 2**(i-1)
- for j in range(0, n-x):
- st[i][j] = min(st[i-1][j], st[i-1][j+x])
- m = int(input())
- for j in range(m):
- a, b = map(int, input().split())
- print(get(a-1, b-1), end = ' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement