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:08:29
Task:Approximate
Sender:Game of Nolife
Submission time:2016-05-28 11:08:29
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

ld x[1010101];
ld xx[1010101];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,q;
	cin>>n>>q;
	for (int i=1;i<=n;i++) {
		cin>>x[i];
		xx[i]=x[i]*x[i];
		x[i]+=x[i-1];
		xx[i]+=xx[i-1];
	}
	cout<<setprecision(6)<<fixed;
	for (int i=0;i<q;i++) {
		int a,b;
		cin>>a>>b;
		ld y1=(x[b]-x[a-1])/(b-a+1);
		ld y2=(xx[b]-xx[a-1])/(b-a+1);
		cout<<y2-y1*y1<<"\n";
	}
}