# 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:53:59
2016-05-28 11:09:00
 Task: Approximate Sender: LTR Submission time: 2016-05-28 11:53:59 Language: C++ Status: READY Result: ACCEPTED

## Test results

 test verdict time (s) #1 ACCEPTED 0.26 / 1.00 details

## Code

```#include <iostream>
#include <vector>
#include <cstdio>

int main()
{
int n, q;
std::cin >> n >> q;
std::vector<int> c;
c.reserve(n);
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;
c.push_back(x);
}

// ith is the sum of values before but not inc. i
std::vector<double> cumsums(n + 1);
std::vector<double> cumsumsq(n + 1);
cumsums[0] = 0.0;
cumsumsq[0] = 0.0;
for (int i = 1; i <= n; ++i) {
cumsums[i] = c[i-1] + cumsums[i-1];
cumsumsq[i] = c[i-1] * c[i-1] + cumsumsq[i-1];
}

for (int i = 0; i < q; ++i) {
int a, b;
std::cin >> a >> b;
a--;
b--;

double num = b - a + 1;
double mean = (cumsums[b+1] - cumsums[a]) / num;
double ms = (cumsumsq[b+1] - cumsumsq[a]) / num;
double err = ms - mean*mean;

printf("%.6f\n", err);
}
}

```

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