luogu#P8105. 「LCOI2022」 Cow Dance

「LCOI2022」 Cow Dance

Background

Bessie brings her cow sisters to dance.

They have already planned the dance steps, but to make the performance look better, they need to know the average position of some leading cows at certain times, so the show can be more perfect.

Unfortunately, Bessie has too many sisters: up to 8×1048\times 10^4 cows may dance at the same time. She does not have a convenient and fast way to compute these average positions, so she asks you for help.

Problem Description

Bessie and her sisters have lined up. The coordinates of the ii-th cow are (xi,yi)(x_i,y_i), where xix_i is the xx-coordinate and yiy_i is the yy-coordinate.

Their dance formation can be transformed in the following ways:

  1. Translation: for cows xx to yy, xixi+ax_i\to x_i+a, yiyi+by_i\to y_i+b.
  2. Rotation: cows xx to yy rotate clockwise by g° around the center (a,b)(a,b).
  3. Scaling (spread out): cows xx to yy scale by a factor of pq\dfrac{p}{q} with center (a,b)(a,b). That is, let the cow’s coordinate before scaling be AA, after scaling be BB, and let (a,b)(a,b) be GG. Then $\overrightarrow{GB}=\dfrac{p}{q}\overrightarrow{GA}$.

Bessie wants to know: for cows xx to yy, their average position is $\left(\frac{\sum\limits^y_{i=x}x_i}{y-x+1},\frac{\sum\limits^y_{i=x}y_i}{y-x+1}\right)$.

The dance is about to start, so she can only give you 1s\texttt{1s}.

Input Format

The first line contains two integers n,mn,m.

The next nn lines each contain two integers xi,yix_i,y_i, representing the coordinates of the i(1in)i(1\le i\le n)-th point.

The next mm lines each start with an integer optopt.

If opt=1opt=1, then four integers x,y,a,bx,y,a,b follow, meaning one translation operation.

If opt=2opt=2, then five integers x,y,a,b,gx,y,a,b,g follow, meaning one rotation operation.

If opt=3opt=3, then six integers x,y,a,b,p,qx,y,a,b,p,q follow, meaning one scaling (spread out) operation.

If opt=4opt=4, then two integers x,yx,y follow, meaning a query of the average position of cows with indices xyx \sim y.

Output Format

Output the answer for each query, one per line. An error within 10410^{-4} is allowed.

3 7
1 1
1 3
3 1
1 1 2 1 -2
4 1 3
2 1 3 2 0 270
4 1 2
3 1 2 2 2 2 1
4 1 3
4 3 3
2.3333333333 0.3333333333
2.0000000000 0.0000000000
1.6666666667 -1.0000000000
1.0000000000 1.0000000000

Hint

[Sample Explanation]

00 is the initial state. 11 is the result after performing the sample operation 1 1 2 1 -2. 22 is the result after performing the sample operation 2 1 3 2 0 270. 33 is the result after performing the sample operation 3 1 2 2 2 2 1.

[Constraints and Conventions]

It is guaranteed that during computations, the absolute value of all numbers is less than or equal to 101510^{15}.

subtask Special Restrictions Score
11 1n,m1031\le n,m\le10^3 88
22 Only rotation operations, and all rotations use a cow as the rotation center. 1818
33 Only scaling operations, and all scalings use a cow as the similarity center.
44 No rotation or scaling operations. 88
55 For all operations and queries, x=yx=y. 1818
66 Both the rotation center and the scaling center are cows. 88
77 1n,m8×1041\le n,m\le 8\times10^4 1010
88 No special restrictions. 1212

For 100%100\% of the testdata, 1n,m3×1051\le n,m\le3\times10^5, 1xyn1\le x\le y\le n, 32768a,b<32768-32768\le a,b<32768, 0<pq2333330< \dfrac{p}{q}\le 233333, 0g3590\le g\le359, and the initial coordinate constraints are the same as for a,ba,b.

Note:

  • Please pay attention to constant-factor optimization.
  • The input and output size is large; using scanf and printf is recommended.

Translated by ChatGPT 5