CSES - HIIT Open 2016 - Results
Submission details
Task:Approximate
Sender:Spitfire
Submission time:2016-05-28 11:24:25 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1--details

Code

#include <iostream>

float handle_query(unsigned int numbers[], unsigned int a, unsigned int b) {
	float avg = 0;
	for (size_t i = a; i <= b; i++) {
		avg += numbers[i];
	}
	avg /= (b-a + 1);

	float err = 0;
	for (size_t i = a; i <= b; i++) {
		err += (numbers[i] - avg) * (numbers[i] - avg);
	}
	err /= (b-a + 1);
	return err;	
}

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	unsigned int n, q;
	std::cin >> n >> q;

	unsigned int numbers[100000];

	unsigned int nb;
	for (size_t i = 0; i < n; i++) {
		std::cin >> nb;
		numbers[i] = nb;
	}

	unsigned int a,b;
	for (size_t i = 0; i < q; i++) {
		std::cin >> a >> b;
		std::cout <<std::fixed <<  handle_query(numbers, a-1, b-1) << std::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)