#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(6);
using namespace std;
int main(){ _
int n, q;
cin >> n >> q;
vector<int> vi(n, 0);
vector<int> sum(n, 0);
for(int i = 0; i < n; ++i) cin >> vi[i];
sum[0] = vi[0];
for(int i = 1; i < n; ++i) sum[i] = sum[i-1] + vi[i];
int a, b, diff;
double mean, ans;
for(int i = 0; i < q; ++i){
cin >> a >> b;
a -= 2; b -= 1;
// cout << "a = " << a << endl;
// cout << "b = " << b << endl;
if(a < 0) diff = sum[b];
else diff = sum[b] - sum[a];
// cout << "diff = " << diff << endl;
mean = diff / (double)(b - a);
// cout << "eman = " << mean << endl;
ans = 0.0;
for(int j = a+1; j <= b; ++j){
ans += (vi[j] - mean) * (vi[j] - mean);
}
ans /= (b-a);
cout << fixed << ans << endl;
}
return 0;
}