Joint Training
Time limit3sMemory limit1024 MB
Given N units with bus costs and dissatisfaction updates, check each lineup's validity, find the max feasible session cost, and count distinct costs per unit.
- Level
Hard10 of 10
- Topics
- Graph, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
With a special training period approaching, units work together in a joint training exercise. Each joint training session selects a total of soldiers. No unit has a limit on how many soldiers it can send, and some units may send none. Each participating unit rents a bus to carry its soldiers to the training site. The rental cost for unit is . The cost of a joint training session is the sum of the bus rental costs of the participating units.
The session is held with the soldiers standing in a line. After training ends, for every pair of adjacent soldiers, the dissatisfaction between their units increases by . Pairs from the same unit do not increase dissatisfaction. The commander does not approve any plan in which two adjacent soldiers come from units with dissatisfaction at least . Before training starts, the dissatisfaction between every pair of units is .
During the special training period, the commander must write reports on three kinds of events.
- The commander receives a training plan that lists the units of the soldiers in line order. If any pair of adjacent soldiers has dissatisfaction at least , the plan is not approved. Otherwise, the training is carried out and the commander reports its total cost.
- A dispute breaks out between units and , and the dissatisfaction between the two units increases by . To find a budget that allows training under any circumstances, the commander reports the maximum cost among all feasible plans.
- Due to rising prices, the bus rental cost of unit increases by . Paying each unit a different amount makes administration complicated, so the commander reports the maximum number of distinct costs among the training plans that include unit .
The increases in dissatisfaction and cost from each event accumulate and remain in effect until all events end.
Input
The first line contains two integers and , the number of units and the smallest dissatisfaction value that forbids adjacency.
The second line contains the bus rental costs of each unit, separated by spaces.
The third line contains the number of events .
The next lines each give the event type and the parameters for that event.
- If , the unit numbers of the soldiers are given in line order, separated by spaces.
- If , the two unit numbers and and the increase in dissatisfaction are given, separated by spaces.
- If , the unit number and the increase in bus rental cost are given, separated by spaces.
Output
On the -th line, print the answer to the -th event.
- If , print the total cost of the training. If the plan is not approved, print
-1. - If , print the maximum cost of a training session that can be carried out.
- If , print the maximum number of distinct costs among the training plans that include unit .
Constraints
- ;
- The total number of integers in the input does not exceed .