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 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 -th cow are , where is the -coordinate and is the -coordinate.
Their dance formation can be transformed in the following ways:
- Translation: for cows to , , .
- Rotation: cows to rotate clockwise by around the center .
- Scaling (spread out): cows to scale by a factor of with center . That is, let the cow’s coordinate before scaling be , after scaling be , and let be . Then $\overrightarrow{GB}=\dfrac{p}{q}\overrightarrow{GA}$.
Bessie wants to know: for cows to , 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 .
Input Format
The first line contains two integers .
The next lines each contain two integers , representing the coordinates of the -th point.
The next lines each start with an integer .
If , then four integers follow, meaning one translation operation.
If , then five integers follow, meaning one rotation operation.
If , then six integers follow, meaning one scaling (spread out) operation.
If , then two integers follow, meaning a query of the average position of cows with indices .
Output Format
Output the answer for each query, one per line. An error within 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]

is the initial state. is the result after performing the sample operation 1 1 2 1 -2. is the result after performing the sample operation 2 1 3 2 0 270. 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 .
| subtask | Special Restrictions | Score |
|---|---|---|
| Only rotation operations, and all rotations use a cow as the rotation center. | ||
| Only scaling operations, and all scalings use a cow as the similarity center. | ||
| No rotation or scaling operations. | ||
| For all operations and queries, . | ||
| Both the rotation center and the scaling center are cows. | ||
| No special restrictions. |
For of the testdata, , , , , , and the initial coordinate constraints are the same as for .
Note:
- Please pay attention to constant-factor optimization.
- The input and output size is large; using
scanfandprintfis recommended.
Translated by ChatGPT 5