#P3707. Astronomical Data Regression Analysis
Astronomical Data Regression Analysis
Astronomical Data Regression Analysis
Frank is an enthusiastic astronomer who not only observes stars but also analyzes the data collected from his telescope. He records various parameters such as brightness and color and uses these to estimate characteristics like distance and radius. Now, Frank is interested in analyzing the relationship between two parameters, (X) and (Y). He has (n) observations where the (i)th observation records (x_i) and (y_i). He needs to perform the following three types of operations:
- 1 L R: Perform linear regression on the observations from index \(L\) to \(R\) (1-indexed). Let \(\overline{x}=\frac{1}{R-L+1}\sum_{i=L}^{R}x_i\) and \(\overline{y}=\frac{1}{R-L+1}\sum_{i=L}^{R}y_i\). If the regression line is \(y=ax+b\), then the slope \(a\) is given by: \[ a=\frac{\sum_{i=L}^{R}(x_i-\overline{x})(y_i-\overline{y})}{\sum_{i=L}^{R}(x_i-\overline{x})^2} \] Print the computed slope \(a\) rounded to 6 decimal places. If the denominator is zero, print 0.000000.
- 2 L R S T: For each observation from index \(L\) to \(R\), add \(S\) to \(x_i\) and \(T\) to \(y_i\).
- 3 L R S T: For each observation from index \(L\) to \(R\), reset the values such that \(x_i = S+i\) and \(y_i = T+i\) (with \(i\) being the original 1-indexed position).
You are given (n) and (q), followed by (n) pairs of initial (x_i) and (y_i), and then (q) queries. For each Type 1 query, output the slope (a) rounded to 6 decimal places.
inputFormat
The first line contains two integers (n) (the number of observations) and (q) (the number of queries).
The next (n) lines each contain two floating-point numbers representing (x_i) and (y_i) for (i=1,2,\ldots,n).
Each of the following (q) lines contains a query in one of the following formats:
- 1 L R
- 2 L R S T
- 3 L R S T
outputFormat
For each query of Type 1, output a single line containing the slope (a) of the best fit line, rounded to 6 decimal places.
sample
5 5
1.0 2.0
2.0 3.0
3.0 5.0
4.0 4.0
5.0 5.0
1 1 5
2 2 4 1.0 1.0
1 1 5
3 3 5 0.0 0.0
1 1 5
0.800000
0.785714
1.000000
</p>