#P8105. Dairy Dance Transformations

    ID: 21288 Type: Default 1000ms 256MiB

Dairy Dance Transformations

Dairy Dance Transformations

Bessie and her sisters have lined up. The i-th cow initially has coordinates \( (x_i, y_i) \). They perform a series of operations on contiguous segments of cows. There are three types of transformations:

  1. Translation: For cows from index \( x \) to \( y \), update the coordinates as follows: \( x_i \to x_i+a \) and \( y_i \to y_i+b \).
  2. Rotation: For cows from index \( x \) to \( y \), rotate their positions clockwise by \( g^\circ \) around the center \( (a, b) \). The updated coordinates \((x', y')\) are computed by:
    \( x' = a + (x-a)\cos(g^\circ) + (y-b)\sin(g^\circ) \),
    \( y' = b - (x-a)\sin(g^\circ) + (y-b)\cos(g^\circ) \).
  3. Expansion: For cows from index \( x \) to \( y \), scale their positions away from the center \( (a, b) \) by a factor of \( \frac{p}{q} \). That is, if the original coordinate is \( A \) and the new coordinate is \( B \), then:
    \( \overrightarrow{GB} = \frac{p}{q} \, \overrightarrow{GA} \) where \( G = (a, b) \).

After several transformation operations, Bessie wants to know the average position of a group of cows. For cows indexed from \( x \) to \( y \), the average position is given by:

[ \left(\frac{\sum_{i=x}^{y} x_i}{y-x+1},; \frac{\sum_{i=x}^{y} y_i}{y-x+1}\right). ]

You are given the initial positions of the cows and a sequence of operations. For each query operation (described below), output the average coordinates with 6 decimal places.

Note: All indices are 1-indexed.

inputFormat

The input begins with two integers \( n \) and \( m \) (the number of cows and the number of operations).

The next \( n \) lines each contain two integers \( x_i \) and \( y_i \) representing the initial coordinates of the i-th cow.

The following \( m \) lines each describe an operation. Each operation is in one of the following formats:

  • 1 x y a b — Translation: add \( a \) to the x-coordinate and \( b \) to the y-coordinate for cows with indices from \( x \) to \( y \).
  • 2 x y a b g — Rotation: rotate cows with indices from \( x \) to \( y \) clockwise by \( g^\circ \) around the point \( (a,b) \).
  • 3 x y a b p q — Expansion: scale cows with indices from \( x \) to \( y \) relative to the point \( (a,b) \) by a factor of \( \frac{p}{q} \).
  • 4 x y — Query: output the average position of cows from index \( x \) to \( y \).

outputFormat

For each query operation (type 4), print a line with two numbers: the average \( x \)-coordinate and the average \( y \)-coordinate, each formatted to 6 decimal places and separated by a space.

sample

3 5
1 1
2 2
3 3
4 1 3
1 2 3 1 1
4 2 3
2 1 2 0 0 90
4 1 2
2.000000 2.000000

3.500000 3.500000 2.000000 -2.000000

</p>