import sys
lines = sys.stdin.readlines()
def asints(s):
return [int(x.strip()) for x in s.split()]
n, q = asints(lines[0])
sequence = asints(lines[1])
sums = [sequence[0]]
sums2 = [sequence[0]**2]
for i in range(1,len(sequence)):
val = sequence[i]
sums.append(sums[i-1] + val)
sums2.append(sums2[i-1] + val*val)
def ex(a,b):
if a == 1:
return sums[b-1] / (b-a+1.0)
return (sums[b-1] - sums[a-2]) / (b-a+1.0)
def ex2(a,b):
if a == 1:
return sums2[b-1] / (b-a+1.0)
return (sums2[b-1] - sums2[a-2]) / (b-a+1.0)
for i in range(2, q + 2):
low, high = asints(lines[i])
var = ex2(low,high) - ex(low,high)**2
#subs = sequence[low-1:high]
#avg = sum(subs) *1.0 / len(subs)
#errs = [(x*1.0-avg)**2 for x in subs]
print "%.6f" % var#sum(errs) / len(errs)