Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 11:45:25
2016-05-28 11:44:26
2016-05-28 11:41:26
Task:Approximate
Sender:Noname 01
Submission time:2016-05-28 11:45:25
Status:READY
Result:ACCEPTED

Show test data

Code

// 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(6);
	  cout.setf(ios::fixed);
	  cout << ans << "\n";
	  
  }
  
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Load();
  Solve();
  return 0;
}