CSES - Practice Contest 2024 - Results
Submission details
Task:Approximate
Sender:hefapa_aachen
Submission time:2024-09-28 13:45:18 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1--details

Code

// ~/.vim/cpp_template.cpp
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i,a,b) for (int i = a; i < b; i++)

// Type Aliases for 1D and 2D vectors with initialization
#define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val
#define ll long long
#define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val
#define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val


using namespace std;

template <typename T>
void pV(const std::vector<T>& vec, const std::string& label = "Vector") {
    std::cout << label << ": [ ";
    for (const auto& elem : vec) {
        std::cout << elem << " ";
    }
    std::cout << "]" << std::endl;
}


using namespace std;


void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) {
    if ((*visited)[s]) return;
    (*visited)[s] = true;
    // process node s


    for (auto u: (*adj)[s]) {
        dfs(u, visited, adj);
    }
}
/*
vector<int> adj[N];                                                          
vector<bool> visited(N, false);
int u, v;
for(int i = 0; i < M;i++){
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
}
*/

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // Your code starts here
    int n, q;
    cin >> n >> q;
    vector<long long> vi(n, 0);
    vector<int> vals(n, 0);
    REP(i, 0, n){
        cin >> vals[i];
        if(i>0){
            vi[i] += vi[i-1];
        }
        vi[i] += vals[i];
    }
    REP(i, 0, q){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        double avg;
        if(a==0){
            avg = vi[b];
        }else{
            avg = vi[b] - vi[a-1];
        }
        avg/= b-a+1;
        long double res = 0.0;
        REP(i, a, b+1){
            res += (vals[i]-avg)*(vals[i]-avg);
        }
        res/= b-a+1;
        cout << fixed << setprecision(20) << res << 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
(empty)