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 12:48:27
Task:Approximate
Sender:zah
Submission time:2016-05-28 12:48:27
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    double t[100001]={}, y[100001]={};
    for (int i=1; i<=n; ++i){
        double a;
        cin >> a;
        t[i]=t[i-1]+a;
        y[i]=y[i-1]+a*a;
    }
     for (int i=0; i<q; ++i){
        int a, b;
        cin >> a >> b;
        double joku=t[b]-t[a-1];
        double k=b-a + 1;
        double x=joku/k;
        double vastaus=(y[b]-y[a-1]-2*x*joku+k*x*x)/k;
        std::cout.unsetf ( std::ios::floatfield );
        std::cout.setf( std::ios::fixed, std:: ios::floatfield );
        std::cout.precision(6);
        cout << vastaus << "\n";
    }
}