#P6526. Frandel's Ghost Summoning
Frandel's Ghost Summoning
Frandel's Ghost Summoning
You are given a coordinate plane representing Frandel's basement. Frandel performs q operations. Each operation may be one of the following types:
1 x y v
: Summon a new ghost at coordinate \( (x, y) \) with power \( v \). The ghosts are numbered in the order they are summoned (starting from 1).2
: Query the maximum "Frandel distance" among all the currently summoned ghosts.3 a
: Query the maximum "Frandel distance" among all ghosts if the ghost with number \( a \) is temporarily ignored (it is not removed permanently).
The Frandel distance between two ghosts \( u \) and \( v \) (with \( u < v \)) is defined as:
[ D(u,v) = |x_u - x_v| + |y_u - y_v| + v_{v} ]
Note:
- The distance of a ghost with itself is defined as its power \( v_i \).
- For a pair, the ghost with the larger number contributes its power.
Your task is to process all operations and output the answer for each query operation (types 2 and 3).
Constraints are such that a simple iterative solution is sufficient.
Hint: For a pair \( (i,j) \) with \( i < j \), the Manhattan part \( |x_i - x_j|+|y_i - y_j| \) can be computed efficiently via keeping track of transformed coordinates.
Input Format (see below):
inputFormat
The first line contains a single integer \( q \) representing the number of operations. Each of the next \( q \) lines contains an operation in one of the following formats:
1 x y v
2
3 a
It is guaranteed that for each operation of type 3, \( a \) is a valid ghost number.
outputFormat
For each query operation (type 2 and type 3), output the maximum Frandel distance on a new line.
sample
7
1 0 0 1
1 1 1 2
2
1 2 2 3
2
3 2
2
4
7
7
7
</p>