CSES - Practice Contest 2024 - Results
Submission details
Task:Approximate
Sender:\(._.)/
Submission time:2024-09-28 12:58:58 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.31 sdetails

Code

// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int n, q;
    cin >> n >> q;
    
    vector<int> arr(n);
    vector<int> arr2(n);
    
    int f = 0;
    cin >> f;
    arr[0] = f;
    arr2[0] = f * f;
    for (int i = 1; i < n; i++)
    {
        int t = 0;
        cin >> t;
        arr[i] = t + arr[i-1];
        arr2[i] = t * t + arr2[i-1];
    }
    
    //for (int i = 0; i < n; i++)
    //    cout << arr[i] << " ";
    
    for (int i = 0; i < q; i++)
    {
        int a, b;
        cin >> a >> b;
        double n = b-a+1;
        a--;a--;
        b--;
        int sub = a >= 0 ? arr[a] : 0;
        int c = arr[b] - sub;
        
        int sub2 = a >= 0 ? arr2[a] : 0;
        int c2 = arr2[b] - sub2;
        
        //cout << c << " " << c2 << " " << n << endl;;
        
        //double equation = ( 1.0/n*c + sqrt(pow(1.0/n*c, 2) - 4.0 * (1.0/n) * c2) ) / 2.0;
        // cout << c2 * n << endl;
        //double equation = ( c - sqrt(pow(c, 2) - c2 * n) ) / n;
        double num = ((double)c) / n;
        //cout << num << endl;
        //cout << 
        cout << c2 / n - 2 * c * num / n + num * num << endl;
        
        // cout << equation << endl;
        
    }

    return 0;
}

Test details

Test 1

Verdict:

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.753
833.362
833.847
834.425
831.468
...
Truncated