Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 11:41:15
Task:Approximate
Sender:Team Purkka
Submission time:2016-05-28 11:41:15
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main () {
  int n, q;
  cin>>n>>q;
  ld v[n];
  ld s[n];
  for (int i = 0; i < n; i++) cin>>v[i], s[i] = v[i] * v[i];
  for (int i = 1; i < n; i++) v[i] += v[i - 1], s[i] += s[i - 1];
  
  for (int i = 0; i < q; i++) {
    int a, b;
    cin>>a>>b;
    a--;
    b--;
    ld avg = v[b];
    if (a != 0) avg -= v[a - 1];
    ld sum = avg;
    avg /= b - a + 1;
    ld ssum = s[b];
    if (a != 0) ssum -= s[a - 1];
    cout<<setprecision(6)<<fixed<<(ssum - 2 * avg * sum + (b - a + 1) * avg * avg) / (b - a + 1)<<endl;
  }
}