#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> s(n+1), cum(n+1), cum2(n+1);
for(int i=1; i<=n; i++) {
cin >> s[i];
cum[i] = s[i];
cum2[i] = s[i]*s[i];
if(i) {
cum[i] += cum[i-1];
cum2[i] += cum2[i-1];
}
//cout << cum[i] << endl;
//cout << cum2[i] << endl;
}
for(int i=0; i<q; i++) {
int a, b;
cin >> a >> b;
double k = b-a+1;
double s = (double)(cum[b]-cum[a-1]);
double s2 = (double)(cum2[b]-cum2[a-1]);
double c = s/k;
double ans = (k*c*c - 2*s*c + s2)/k;
printf("%.06f\n", ans);
//cout << setprecision(6) << ans << endl;
}
}