#P3707. [SDOI2017] 相关分析

    ID: 1339 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2017线段树各省省选山东Special Judge前缀和块状链表,块状数组,分块

[SDOI2017] 相关分析

Description

Frank is very interested in astronomy. He often observes stars with a telescope and records their information, such as brightness and color, and then estimates properties like distance and radius.

Frank not only enjoys observing but also analyzing the data he collects. He often checks whether there is some relationship between two parameters (for example, brightness and radius).

Now Frank wants to analyze the relationship between parameters XX and YY. He has nn groups of observations. The ii-th group records xix_i and yiy_i. He needs to perform the following types of operations.

1 L R\verb!1 L R!

Fit a line to the observations from group LL to group RR. Let x\overline{x} denote the mean of xx among these observations, and let y\overline{y} denote the mean of yy, that is,

$$\begin{aligned}\overline{x}&={1 \over R-L+1} \sum _{i=L} ^R x_i \\\overline{y}&={1 \over R-L+1} \sum _{i=L} ^R y_i\end{aligned}$$

If the line equation is y=ax+by=ax+b, then aa should be computed as:

$$a={\displaystyle\sum_{i=L} ^R (x_i-\overline{x})(y_i-\overline{y}) \over \displaystyle\sum _{i=L} ^R (x_i -\overline{x})^2}$$

You need to help Frank compute aa.

2 L R S T\verb!2 L R S T!

Frank found that the measurements from group LL to group RR have errors. For each ii with LiRL \leq i \leq R, add SS to xix_i and add TT to yiy_i.

3 L R S T\verb!3 L R S T!

Frank needs to modify the data from group LL to group RR. For each ii with LiRL \leq i \leq R, set xix_i to (S+i)(S+i) and set yiy_i to (T+i)(T+i).

Input Format

The first line contains two numbers n,mn,m, denoting the number of observation groups and the number of operations.

The next line contains nn numbers, where the ii-th number is xix_i.

The next line contains nn numbers, where the ii-th number is yiy_i.

The next mm lines describe the operations. See the formats in the problem statement.

Output Format

For each operation of type 11, output one line containing the slope aa. Your output is considered correct if the absolute or relative error does not exceed 10510^{-5}.

3 5
1 2 3
1 2 3
1 1 3
2 2 3 -3 2
1 1 2
3 1 2 2 1
1 1 3

1.0000000000
-1.5000000000
-0.6153846154

Hint

Constraints and Notes

  • For 20%20\% of the testdata, 1n,m10001 \leq n,m \leq 1000.
  • For another 20%20\% of the testdata, there is no operation 33, and in operation 22 we have S=0S=0.
  • For another 30%30\% of the testdata, there is no operation 33.

For 100%100\% of the testdata, 1n,m1051 \leq n,m \leq 10^5, 0S,T1050 \leq |S|,|T| \leq 10^5, 0xi,yi1050 \leq |x_i|,|y_i| \leq 10^5.

It is guaranteed that in operation 11 the denominator will not be 00.

Translated by ChatGPT 5