CSES - HIIT Open 2016 - Results
Submission details
Task:Approximate
Sender:Noname 01
Submission time:2016-05-28 11:41:26 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.16 sdetails

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--;
	  int 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;
}

Test details

Test 1

Verdict:

input
100000 100000
62 64 35 47 57 38 52 4 56 13 7...

correct output
831.753342
833.361649
833.847478
834.425131
831.468120
...

user output
831.75334177
833.36164940
833.84747826
834.42513075
831.46812045
...