#P7220. Dust Sweeping Simulation

    ID: 20424 Type: Default 1000ms 256MiB

Dust Sweeping Simulation

Dust Sweeping Simulation

Bitaro has been gifted a house in the shape of an isosceles right triangle with leg length \(N\). Points in the room are represented as \((x,y)\) with \(0\le x+y\le N\). The right angle is at the origin, and the two legs lie along the \(x\)‐axis and \(y\)‐axis.

Initially, there are \(M\) piles of dust in the room. The \(i\)th pile is located at \((X_i, Y_i)\). Note that multiple piles may be at the same coordinate.

Bitaro cleans his room using a broom, which is modeled as a line segment placed somewhere in the room. The length of this segment is called the width of the broom. Bitaro only uses one of the following two cleaning processes:

  • Process H: The broom is placed parallel to the \(y\)-axis with one endpoint at the origin. It is then moved horizontally to the right until it can no longer be moved. If the broom has width \(l\), then every dust pile originally at \((x,y)\) with \[ x < N - l \quad\text{and}\quad y\le l, \] is moved to \((N-l,y)\). (Multiple piles may end up at the same position.)
  • Process V: The broom is placed parallel to the \(x\)-axis with one endpoint at the origin. It is then moved vertically upward until it can no longer be moved. If the broom has width \(l\), then every dust pile originally at \((x,y)\) with \[ x\le l \quad\text{and}\quad y < N - l, \] is moved to \((x,N-l)\). (Again, multiple piles may share the same coordinate.)

After the initial setup, \(Q\) events occur in sequence. Each event can be one of the following four types:

  1. Query Event: Bitaro wants to know the current position of the dust pile numbered \(P_i\).
  2. Process H Event: Bitaro uses a broom of width \(L_i\) and performs Process H.
  3. Process V Event: Bitaro uses a broom of width \(L_i\) and performs Process V.
  4. Add Event: A new pile of dust appears at the point \((A_i,B_i)\). If there were \(c\) dust piles before this event, the new dust pile is numbered \(c+1\).

Your task is to process the events and, for each query event, output the current coordinates of the specified dust pile.

inputFormat

The first line contains three integers \(N\), \(M\), and \(Q\) representing the leg length of the triangle, the number of initial dust piles, and the number of events.

The next \(M\) lines each contain two integers \(X_i\) and \(Y_i\) representing the coordinates of the dust piles.

The following \(Q\) lines each describe an event. Each event begins with an integer indicating its type:

  • If the type is 1, the line contains one additional integer \(P_i\) (i.e. the query event: 1 P).
  • If the type is 2, the line contains one additional integer \(L_i\) (i.e. Process H event: 2 L).
  • If the type is 3, the line contains one additional integer \(L_i\) (i.e. Process V event: 3 L).
  • If the type is 4, the line contains two additional integers \(A_i\) and \(B_i\) (i.e. an add event: 4 A B).

It is guaranteed that all dust coordinates always satisfy \(0\le x+y\le N\).

outputFormat

For each query event (type 1), output a line containing two integers representing the \(x\) and \(y\) coordinates of the corresponding dust pile.

sample

10 2 5
1 2
3 4
1 1
2 5
1 1
3 2
1 2
1 2

5 2 5 4

</p>