#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int kek[101][101010];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
double dn = n;
vector<int> S;
vector<int> sums;
double sum = 0;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
S.push_back(t);
sums.push_back(sum);
sum += t;
}
sums.push_back(sum);
cout << fixed << setprecision(6);
kek[S[0]][0]++;
for (int j = 1; j < S.size(); ++j) {
for (int i = 1; i < 101; ++i)
kek[i][j] = kek[i][j-1];
kek[S[j]][j]++;
}
for (int i = 0; i < q; ++i) {
int a, b;
cin >> a >> b;
double s = sums[b]-sums[a-1];
double m = (b-a+1);
double c = s/m;
/*
double err = 0;
for (int j = a; j <= b; ++j) {
double t = S[j-1] - c;
err += t*t;
}
*/
double err = 0;
for (int j = 1; j < 101; ++j) {
int count = 0;
if (a == 1) count = kek[j][b-1];
else count = kek[j][b-1] - kek[j][a-2];
if (count > 0) {
double t = ((double)j - c);
err += ((double)count)*t*t;
}
}
cout << err/m << endl;
}
}