#P6526. 「Wdoi-1」四重存在

「Wdoi-1」四重存在

Description

The basement where Flandre is can be abstracted as a huge 2D Cartesian coordinate system. Flandre will perform qq actions. Each action is as follows:

  • 1 x y v means Flandre summons a new phantom at coordinate (x,y)(x,y), and this phantom has vv units of power.

  • 2 means query, among the existing phantoms, what the maximum value of "Flandre Distance" is.

  • 3 a means query: if the aa-th summoned phantom is ignored, then among the remaining phantoms, what the maximum value of "Flandre Distance" is.

Note:

Let the ii-th summoned phantom have index ii, coordinate (xi,yi)(x_i,y_i), and power viv_i.

The "Flandre Distance" between two phantoms with indices u,vu,v is xuxv+yuyv+vmax(u,v)|x_u-x_v|+|y_u-y_v|+v_{\max(u,v)}.

In particular, the "Flandre Distance" from phantom ii to itself is viv_i.

In operation 33, the aa-th summoned phantom only does not participate in this query, rather than being removed.

Input Format

The first line contains an integer qq, the number of operations.

Then follow qq lines, each containing several integers. The input format is the same as in the problem description.

Note: Since Flandre's emotions are unstable, in operation 11, the actual input is:

$$x'=x \operatorname{ xor } (\text{lastans} \bmod 3)$$$$y'=y \operatorname{ xor } (\text{lastans} \bmod 3)$$$$v'=v \operatorname{ xor } (\text{lastans} \bmod 3)$$

The meanings of the operations are:

  • xor\operatorname{xor} denotes the bitwise XOR operation.

  • lastans\text{lastans} denotes the answer of the previous operation 22 or 33. Initially, lastans=0\text{lastans}=0.

Output Format

Output several lines in total, each containing one integer, which is the answer for each operation 22 or 33.

6
1 4 -4 0
1 -3 -1 0
1 -1 -1 0
2
3 2
3 3
10
8
10

Hint

Constraints and Notes

"This problem uses bundled testdata: a subtask is accepted if and only if all test points in that subtask are accepted".

Subtask ID qq \le Special Property Score
11 500500 None 55
22 5×1035 \times 10^3 A 1010
33 10510^5 2020
44 None 2525
55 2×1062 \times 10^6 4040

Property A means there is no operation 33.

For 100%100\% of the data, 108x,y,v108-10^8 \le x,y,v \le 10^8. Let the number of phantoms at some moment be cc, then 1ac1 \le a \le c.

The testdata guarantees that any two phantoms have different coordinates, and that at least 33 points have been inserted when querying 22 or 33.

Translated by ChatGPT 5