Convex Hull (Queries)#3042

Convex Hull (Queries)

0.25 seconds
64 megabytes
Hard (≈1650)

Given a set of points on a plane and operations that modify this set, each operation can be one of the following two types:

  1. Add a point with integer coordinates to the set. The coordinate of the new point must be strictly greater than the coordinates of all other points already in the set.

  2. Remove the point with the largest coordinate from the set.

Write a program that simulates these operations and outputs the doubled area of the convex hull of the set of points after each operation. Initially, the set of points is empty. Assume that the area of the convex hull of an empty set of points is zero.

The convex hull of a set of points on a plane is the smallest convex polygon that contains all the points in the set. A polygon is convex if the line segment connecting any two of its points lies entirely within the polygon. Here, a polygon includes both its boundary and interior.

Input

The first line contains a single integer (1 \leq N \leq 100\ 000) — the number of operations to be performed. The next lines each contain three integers, representing the operations in an encoded format. To determine the parameters of operation number , read three integers T^*, X^*, and Y^* (0 \leq T^* \leq 1,\ 0 \leq X^*, Y^* \leq 2\ 000\ 000\ 000) from the (i+1)-th line, then calculate using the formula T = (T^* + S) \bmod 2, where is the doubled area of the convex hull of the set of points before executing operation . It is guaranteed that is always an integer.

  1. If T = 0, the current operation is of the first type, and the coordinates (X, Y) of the new point are calculated as follows:

    • X = L + ((S + X^*) \bmod 2\ 000\ 000\ 001),

    • Y = ((Y^* + S) \bmod 2\ 000\ 000\ 001) - 1\ 000\ 000\ 000.

    Here, is the maximum coordinate of all points in the set. If the set is empty, then L = -1\ 000\ 000\ 000.

  2. If T = 1, perform the second type of operation times. The number is determined by the formula: K = ((X^* + Y^* + S) \bmod Q) + 1. Here, is the number of points in the set.

It is guaranteed that with the correct decoding of all operations, the following constraints are met:

  1. The coordinates of all points added to the set do not exceed in absolute value.

  2. When adding a new point, its coordinate is strictly greater than the coordinates of all points already in the set.

  3. The removal operation is applied only to a non-empty set of points.

Output

Output exactly lines. On line , output the doubled area of the convex hull of the set of points formed after executing the first operations. If the set of points is empty, consider the area of its convex hull to be .

Examples

Example 1

Loading
Loading

Note

After decoding, the test looks like this:

  • T = 0,\ X = 0,\ Y = 0

  • T = 0,\ X = 1\ 000\ 000,\ Y = 1\ 000\ 000

  • T = 0,\ X = 2\ 000\ 000,\ Y = -1\ 000\ 000

  • T = 0,\ X = 3\ 000\ 000,\ Y = 0

  • T = 1,\ K = 1

  • T = 1,\ K = 2

Scoring

The test set consists of separate blocks, with the following additional constraints:

  • of tests: N \leq 300

  • of tests: N \leq 3\ 000

  • of tests: N \leq 100\ 000, with no more than lines where T = 1 (after decoding)

  • of tests: N \leq 100\ 000