Untitled
unknown
plain_text
a year ago
837 B
0
Indexable
Never
n = int(input()) h = list(map(int, input().split())) h_partial_sums = [0] * (n + 1) h_squares_partial_sums = [0] * (n + 1) h_cubes_partial_sums = [0] * (n + 1) for i in range(n): h_partial_sums[i + 1] = h_partial_sums[i] + h[i] item = h[i] * h[i] h_squares_partial_sums[i + 1] = h_squares_partial_sums[i] + item item *= h[i] h_cubes_partial_sums[i + 1] = h_cubes_partial_sums[i] + item for _ in range(int(input())): l, r = map(int, input().split()) num_items = r - l + 1 mu = (h_partial_sums[r] - h_partial_sums[l - 1]) / num_items h2 = h_squares_partial_sums[r] - h_squares_partial_sums[l - 1] d = h2 / num_items - mu * mu h3 = h_cubes_partial_sums[r] - h_cubes_partial_sums[l - 1] a = d ** (-1.5) * ((h3 - 3 * mu * h2) / num_items + 2 * mu * mu * mu) print(a)