#P5416. Time-Space Investigation

    ID: 18648 Type: Default 1000ms 256MiB

Time-Space Investigation

Time-Space Investigation

In the year 2045, humanity has made a breakthrough in technology and discovered a method for time‐space travel. Little R obtains a time travel device and wishes to investigate the development of humanity in different parallel universes. According to the parallel universe theory, the universe consists of many independent timelines. At each time step, an existing timeline (space) may sprout new timelines. The universe is three-dimensional and positions are given by a Cartesian coordinate system \((x,y,z)\). In the initial timeline (numbered \(0\)), humans reside on Earth whose coordinate is \((0,0,0)\). All other timelines develop from an existing one. When a timeline evolves, the original timeline remains unchanged.

Two types of events can affect the investigation status in any timeline:

  1. A new planet is colonized, making its status "colonized".
  2. An already colonized planet is abandoned, making its status "not colonized".

When Little R travels in time, he first selects a timeline. In that timeline, some planets are colonized. To conduct his investigation, he only needs to land on any colonized planet. However, due to a malfunction in his time travel device, the button controlling the \(x\) coordinate is broken; hence, the arriving point \(A\) always has a fixed \(x\) coordinate (this fixed value may vary between travels), while he is free to choose the \(y\) and \(z\) coordinates arbitrarily.

The travel cost is computed as follows. Let \(A\) be the destination (with fixed \(x\)) and \(B\) be a colonized planet where the investigation is conducted. If the Euclidean distance between \(A\) and \(B\) is \(d\), then the navigation cost is \(d^2\). Furthermore, if the investigation cost on planet \(B\) is \(c\), then the total cost is given by:

[ \text{Total Cost} = d^2 + c ]

Note that since Little R can freely choose the \(y\) and \(z\) coordinates of \(A\), he may set them equal to those of \(B\). Therefore, if \(B\) has coordinate \((x_B, y_B, z_B)\) and the fixed \(x\) coordinate is \(X\), the distance \(d\) becomes \(|x_B - X|\) and the cost simplifies to:

[ \text{Cost} = (x_B - X)^2 + c ]

Your task is to process a sequence of events in the chosen timeline. Initially, only Earth at \(x=0\) is colonized with investigation cost \(0\). You are given a sequence of operations of three types:

  • 1 x c: A colonization event: the planet at coordinate \(x\) becomes colonized with investigation cost \(c\).
  • 2 x: An abandonment event: the planet at coordinate \(x\) is abandoned (i.e. it is no longer colonized).
  • 3 X: A query event: given the fixed \(x\) coordinate \(X\) of the arrival point \(A\), compute the minimum total cost \((x_B - X)^2 + c\) over all currently colonized planets \(B\).

Output the answer for each query event.

inputFormat

The first line contains an integer \(m\) representing the number of operations.

Each of the following \(m\) lines contains an operation in one of the following formats:

  • 1 x c: Colonize the planet at coordinate \(x\) with investigation cost \(c\).
  • 2 x: Abandon the planet at coordinate \(x\); it will no longer be considered colonized.
  • 3 X: Query the minimum total cost given the fixed \(x\) coordinate \(X\) for the destination point. The answer is the minimum of \((x_B - X)^2 + c\) over all currently colonized planets \(B\).

Initially, the only colonized planet is Earth at \(x=0\) with cost \(0\).

outputFormat

For each query operation (type 3), output one line containing the minimum total cost.

sample

5
3 0
1 3 5
3 2
2 0
3 4
0

4 6

</p>