# 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 14:42:01
2016-05-28 11:25:47
 Task: Approximate Sender: Verto Submission time: 2016-05-28 14:42:01 Language: Python2 Status: READY Result: ACCEPTED

## Test results

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

## Code

```import sys

def asints(s):
return [int(x.strip()) for x in s.split()]

n, q = asints(lines[0])
sequence = asints(lines[1])

sums = [sequence[0]]
sums2 = [sequence[0]**2]
for i in range(1,len(sequence)):
val = sequence[i]
sums.append(sums[i-1] + val)
sums2.append(sums2[i-1] + val*val)
def ex(a,b):
if a == 1:
return sums[b-1] / (b-a+1.0)
return (sums[b-1] - sums[a-2]) / (b-a+1.0)

def ex2(a,b):
if a == 1:
return sums2[b-1] / (b-a+1.0)
return (sums2[b-1] - sums2[a-2]) / (b-a+1.0)

for i in range(2, q + 2):
low, high = asints(lines[i])
var = ex2(low,high) - ex(low,high)**2
#subs = sequence[low-1:high]
#avg = sum(subs) *1.0 / len(subs)
#errs = [(x*1.0-avg)**2 for x in subs]
print "%.6f" % var#sum(errs) / len(errs)

```

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