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 12:42:17
2016-05-28 12:37:40
2016-05-28 12:37:12
 Task: Approximate Sender: Oispa Kaljaa Submission time: 2016-05-28 12:42:17 Language: C++ Status: READY Result: ACCEPTED

Test results

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

Code

```#include <bits/stdc++.h>

using namespace std;
long long cs[110][101010];
int main(){
cin.sync_with_stdio(0);
cin.tie(0);

int n, q; cin >> n >> q;
int x[101010];
for(int i = 0; i < n; i++)
cin >> x[i];

long long s[101010] = {0};
s[0] = x[0];
cs[x[0]][0]++;
for(int i = 1; i < n; i++){
s[i] = s[i-1]+x[i];
for(int j = 1; j <= 100; j++)
cs[j][i] = cs[j][i-1];
cs[x[i]][i]++;
}
while(q--){
int a, b; cin >> a >> b;
a--;
b--;
long long su = s[b];
if(a > 0)
su-=s[a-1];
double le = (b-a)+1;
double c = su/le;
double ans = 0;
for(long long i = 1; i <= 100; i++){
long long mm = cs[i][b];
if(a > 0)
mm-=cs[i][a-1];
//cout << i << " on " << mm << " delta c " << (i-c)  << endl;
ans+=(i-c)*(i-c)*mm;
}
ans/=le;
printf("%4.6f\n", ans);
}
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