CSES - HIIT Open 2016 - Results
Submission details
Task:Approximate
Sender:Noname 01
Submission time:2016-05-28 11:45:25 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.16 sdetails

Code

// NONAME-01
#include <bits/stdc++.h>
using namespace std;
vector <int> a;
vector <long long> x;
vector <long long> xx;
int n, m;
void Load()
{
cin >> n >> m;
int i;
a.resize(n); x.resize(n); xx.resize(n);
for (i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) x[i] += x[i-1];
x[i] += a[i];
if (i > 0) xx[i] += xx[i-1];
xx[i] += a[i]*a[i];
}
}
void Solve()
{
int i, a, b;
for (i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
long long s, ss;
s = x[b];
if (a > 0) s -= x[a-1];
ss = xx[b];
if (a > 0) ss -= xx[a-1];
long double l = b-a+1;
// cerr << s << ' ' << ss << ' ' << l << "\n";
long double ans = 1/l * (ss - s*(s/l));
cout.precision(6);
cout.setf(ios::fixed);
cout << ans << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Load();
Solve();
return 0;
}

Test details

Test 1

Verdict: ACCEPTED

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
831.753342
833.361649
833.847478
834.425131
831.468120
...