// NONAME-01
#include <bits/stdc++.h>
using namespace std;
vector <int> a;
vector <long long> x;
vector <long long> xx;
int n, m;
void Load()
{
cin >> n >> m;
int i;
a.resize(n); x.resize(n); xx.resize(n);
for (i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) x[i] += x[i-1];
x[i] += a[i];
if (i > 0) xx[i] += xx[i-1];
xx[i] += a[i]*a[i];
}
}
void Solve()
{
int i, a, b;
for (i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
long long s, ss;
s = x[b];
if (a > 0) s -= x[a-1];
ss = xx[b];
if (a > 0) ss -= xx[a-1];
long double l = b-a+1;
// cerr << s << ' ' << ss << ' ' << l << "\n";
long double ans = 1/l * (ss - s*(s/l));
cout.precision(8);
cout.setf(ios::fixed);
cout << ans << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Load();
Solve();
return 0;
}