#P3991. [BJOI2017] 喷式水战改
[BJOI2017] 喷式水战改
Description
The initial fuel sequence is empty. Each operation inserts units of the same type of fuel at position in the sequence. For this fuel, each unit can produce energy in the three operating states, respectively.
The position means that, after insertion, there are units of the original fuel in front of the first inserted unit.
All units are placed consecutively. Then the fuel that originally started at position (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 , the number of operations.
Each of the next lines contains integers , separated by spaces, indicating that units of the same fuel are inserted at position in the sequence.
For this fuel, each unit produces energy in the Original, Extended, and Enhanced states, respectively.
Output Format
Output 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 .
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 , increased by .
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 .
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 of the testdata, , , .
For of the testdata, it is guaranteed that at the time of insertion there are at least units of fuel already in the sequence.
The remaining of the testdata has graded difficulty.
Translated by ChatGPT 5
京公网安备 11011102002149号