CSES - HIIT Open 2016 - Results
Submission details
Task:Approximate
Sender:ContinuedLife
Submission time:2016-05-28 11:18:03 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1--details

Code

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

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
(empty)