#P5859. Mirror Reflection and Opacity

    ID: 19087 Type: Default 1000ms 256MiB

Mirror Reflection and Opacity

Mirror Reflection and Opacity

Little \(A\) dreamed that he was standing on a platform surrounded by several plane mirrors. Let \(A = (0,0)\). Each mirror has an initial opacity denoted by \(v_i\). In this problem, we define the following:

  • The opacity of a ray is defined as the sum of the initial opacities \(v_i\) of all mirrors that the ray passes through.
  • The visual opacity of a mirror is defined as the maximum opacity, taken over all rays starting from \((0,0)\) that intersect that mirror.

In addition, \(A\) is able to manipulate these mirrors. You are required to process \(Q\) operations. The operations are of the following four types:

1 x1 y1 x2 y2 v

Add a mirror whose two endpoints are \((x_1,y_1)\) and \((x_2,y_2)\) with an initial opacity \(v\). Note that from \((0,0)\) the mirror is visible as the segment subtending the smaller angular interval between the directions of the endpoints. In other words, if the two endpoints have angles \(a_1\) and \(a_2\) (in radians, normalized to \([0, 2\pi)\)), then the mirror is intersected by a ray if the ray’s angle is in the smaller arc between \(a_1\) and \(a_2\). If the smaller arc does not form a single contiguous interval, it is represented as two intervals.

2 d

Destroy the \(d\)-th mirror that was added (it is guaranteed that this mirror has not yet been destroyed).

3 x y

Let \(A=(0,0)\) and \(B=(x,y)\). Query the opacity of the ray \(AB\); that is, output the sum of \(v_i\) for all mirrors (which have not been destroyed) that this ray intersects.

4 d

Query the visual opacity of the \(d\)-th mirror. This is defined as

[ \max_{\theta \in I_d} \sum_{\substack{j,\text{active}\ \theta \in I_j}} v_j, ]

where (I_d) is the set of angles for which the (d)-th mirror is intersected. If the mirror has been destroyed, output oops!.

inputFormat

The first line contains an integer \(Q\) \( (1 \le Q \le \text{small}) \) indicating the number of operations. Each of the following \(Q\) lines contains one operation in one of the following formats:

  • 1 x1 y1 x2 y2 v: Add a mirror with endpoints \((x_1,y_1)\) and \((x_2,y_2)\) and initial opacity \(v\) (\(v\) is an integer).
  • 2 d: Destroy the \(d\)-th added mirror (it is guaranteed that this mirror has not yet been destroyed).
  • 3 x y: With \(A=(0,0)\) and \(B=(x,y)\), output the ray's opacity.
  • 4 d: Output the visual opacity of the \(d\)-th mirror (output oops! if it has been destroyed).

outputFormat

For each query of type 3 or type 4, output the result on a separate line. For a type 4 query on a destroyed mirror, output oops!.

sample

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

5 oops!

</p>