#include <bits/stdc++.h>
using namespace std;
#define int long long
// g++ <filename>.cpp -g -Wall -Wextra -DDEBUG -o <executable>
// copied from: https://codeforces.com/blog/entry/79024
// === Debug macro starts here ===
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){
os<<"[";
for(auto& x:v){os<<x<<", ";}
return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p){
return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// === Debug macro ends here ===
signed main() {
int n, q;
cin >> n >> q;
vector<int> prefix_sum(n+1, 0);
vector<int> numbers(n+1, 0);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
prefix_sum[i] = prefix_sum[i-1] + x;
numbers[i] = x;
}
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
double k = (b-a)+1;
double constant = (prefix_sum[b] - prefix_sum[a-1]) / k;
// dbg(k);
// dbg(constant);
double error = 0;
for (int j = a; j <= b; j++) {
double temp = (numbers[j] - constant);
error += temp * temp;
// dbg(error);
}
error = error / k;
printf ("%.6f\n", error);
}
return 0;
}