Pumba's Water Reservoir
Time limit4sMemory limit1024 MB
Pumba adds water to ranges of basins, each capped at m liters, and must answer range sum queries over k days.
- Level
Medium6 of 10
- Topics
- Divide and conquer, Array, Implementation
- Solved
- No attempts yet
Problem
Pumba is very thrifty. Worried about a possible drought, he decided to stock up on water. Pumba has numbered wooden basins. The volume of each basin is liters. Pumba will stock water over days. On each day, Pumba performs exactly one of the following actions:
- Adds liters of water to every basin with numbers from to inclusive. If a basin cannot hold liters, Pumba fills it completely.
- Asks Timon for the total amount of water in the basins with numbers from to inclusive.
Timon is very lazy, so he has assigned you to answer Pumba's questions. Before stocking begins, the -th basin already contains liters of water.
Input
The first line contains three integers , , : the number of basins, the volume of one basin, and the number of days Pumba will stock water (, , ).
The second line contains integers , the amount of water in each basin before stocking ().
Each of the next lines describes Pumba's action on that day. If on day Pumba adds water, the first number of the line is 1, followed by three integers , , (, ). If on day Pumba asks for the total, the first number of the line is 2, followed by two integers and ().
Output
For each of Pumba's questions, print the answer on its own line, in the order the questions are given.