luogu#P3991. [BJOI2017] 喷式水战改

    ID: 2938 远端评测题 3000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2017各省省选平衡树北京O2优化分治矩阵加速动态 DP

[BJOI2017] 喷式水战改

Background

Got a pilot license for airplanes (?), so resupply is no longer a problem.

XXXX year XX month XX day.

Got a pilot license for jets (??), so I can fly even faster.

XXXX year XX month XX day.

Got a pilot license for attack aircraft (???), which does not exist.

XXXX year XX month XX day.

If you use lead plates for the sandwich structure, the fuselage will get heavier.

XXXX year XX month XX day.

Kou-chan’s special delivery was precisely dropped on the target.


Another day of “nuke-peace.”

Amane is doing maintenance on the jet and refueling it.

This jet was specially made by a certain “mou ji” (某姬). Its engine has three operating states:

  1. Original: a low-power, high-efficiency state used for high-altitude level flight or stealth flight.

  2. Extended: a state specially modified to maximize energy utilization during a dive.

  3. Enhanced: a state used after a diving attack to generate extreme torque and regain altitude.

In one attack, the jet will go through the workflow “Original → Extended → Enhanced → Original.”

Fuel utilization efficiency differs across states.

Amane is now tuning the jet’s fuel loading sequence.

Your task is to compute the maximum total energy the fuel can produce.

Why you? Choose one: peace or “nuke-peace.”

Problem Description

The initial fuel sequence is empty. Each operation inserts xix _ i units of the same type of fuel at position pip _ i in the sequence. For this fuel, each unit can produce energy ai,bi,cia _ i, b _ i, c _ i in the three operating states, respectively.

The position pip _ i means that, after insertion, there are pip _ i units of the original fuel in front of the first inserted unit.

All xix _ i units are placed consecutively. Then the fuel that originally started at position pip _ i (if any) is shifted backward in order.

For a fixed fuel sequence, its maximum total energy is defined as follows: split the sequence into four consecutive segments in the order “Original → Extended → Enhanced → Original” (each segment may be empty). The total energy is the sum, over all units, of the energy corresponding to the state of the segment they belong to. Take the maximum value over all such splits.

For each insertion operation, output by how much the maximum total energy increases due to this operation.

If this calculation is not intuitive, see the sample explanation.

Input Format

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

Each of the next nn lines contains 55 integers pi,ai,bi,ci,xip _ i, a _ i, b _ i, c _ i, x _ i, separated by spaces, indicating that xix _ i units of the same fuel are inserted at position pip _ i in the sequence.

For this fuel, each unit produces ai,bi,cia _ i, b _ i, c _ i energy in the Original, Extended, and Enhanced states, respectively.

Output Format

Output nn lines. Each line contains a single integer, the increase in the maximum total energy after that operation.

5
0 25 37 46 2
1 32 14 16 3
3 99 77 88 4
2 43 68 57 5
14 72 36 18 6

92
75
396
319
432

Hint

After the first operation, the fuel sequence is “[1 1]”. The way to achieve maximum energy is “[En1 En1]”, totaling 46+46=9246+46=92.

After the second operation, the fuel sequence is “[1 2 2 2 1]”. The way to achieve maximum energy is “[Or1 Or2 Or2 Or2 En1]”, totaling 25+32+32+32+46=16725+32+32+32+46=167, increased by 16792=75167-92=75.

After the third operation, the fuel sequence is “[1 2 2 3 3 3 3 2 1]”. The way to achieve maximum energy is “[Or1 Or2 Or2 Or3 Or3 Or3 Or3 Or2 En1]”, increased by 99×4=39699\times 4=396.

After the fourth operation, the fuel sequence is “[1 2 4 4 4 4 4 2 3 3 3 3 2 1]”. The way to achieve maximum energy is “[Or1 Or2 Ex4 Ex4 Ex4 Ex4 Ex4 Or2 Or3 Or3 Or3 Or3 Or2 Or1]”.

After the fifth operation, the fuel sequence is “[1 2 4 4 4 4 4 2 3 3 3 3 2 1 5 5 5 5 5 5]”. The way to achieve maximum energy is “[Or1 Or2 Ex4 Ex4 Ex4 Ex4 Ex4 Or2 Or3 Or3 Or3 Or3 Or2 Or1 Or5 Or5 Or5 Or5 Or5 Or5]”.

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1ai,bi,ci1041 \leq a_i, b_i, c_i \leq 10^4, 1xi1091 \leq x_i \leq 10^9.

For 100%100\% of the testdata, it is guaranteed that at the time of insertion there are at least pip _ i units of fuel already in the sequence.

The remaining 50%50\% of the testdata has graded difficulty.

Translated by ChatGPT 5