Code Submission Evaluation System Login

# HIIT Open 2016

 Start: 2016-05-28 11:00:00 End: 2016-05-28 16:00:00

CSES - HIIT Open 2016 - Results
History
2016-05-28 11:40:12
2016-05-28 11:18:03
 Task: Approximate Sender: ContinuedLife Submission time: 2016-05-28 11:40:12 Language: C++ Status: READY Result: ACCEPTED

## Test results

 test verdict time (s) #1 ACCEPTED 0.20 / 1.00 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);
vector<long long> sum2(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];

for(int i = 0; i < n; ++i)	vi[i] = vi[i] * vi[i];
sum2[0] = vi[0];
for(int i = 1; i < n; ++i)	sum2[i] = sum2[i-1] + vi[i];

//	for(int i = 0; i < n; ++i)	cout << sum2[i] << endl;

int a, b, diff;
double mean, ans;
for(int i = 0; i < q; ++i){
cin >> a >> b;
a -= 2; b -= 1;

if(a < 0)	diff = sum[b];
else diff = sum[b] - sum[a];
mean = diff / (double)(b - a);

//		cout << "a = " << a  << endl;
//		cout << "b = " << b << endl;
// s_i^2 - 2s_ic_i + c_i^2
if(a < 0)	ans = sum2[b];
else ans = sum2[b] - sum2[a];
//		cout << "first = " << ans << endl;

ans = ans - 2*diff*mean + (b-a)*mean*mean;

ans /= (b-a);
cout << fixed << ans << endl;
}

return 0;
}

```

## Test details

### Test 1

Verdict: ACCEPTED

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

correct output
```831.753342 833.361649 833.847478 834.425131 831.468120 836.550284 840.319891 843.709808 830.097515 832.352323 828.549331 811.748878 833.912525 830.245034 831.485429 815.101051 834.579010 848.833782 839.942329 822.449380 ...```
view   save

user output
```831.753342 833.361649 833.847478 834.425131 831.468120 836.550284 840.319891 843.709808 830.097515 832.352323 828.549331 811.748878 833.912525 830.245034 831.485429 815.101051 834.579010 848.833782 839.942329 822.449380 ...```
view   save