#P7870. Colorful Dango Stack Simulation
Colorful Dango Stack Simulation
Colorful Dango Stack Simulation
Qinglan has discovered that the Kappa's Dango Machine can produce dango (Japanese dumplings) in various colors. For a dango of color \(c\), the selling price is \(c\). The machine always produces dango of consecutive colors.
At the start of the day, Qinglan uses an empty stack to store the produced dango. There will be \(n\) operations. Each operation is one of the following two types:
- 1 l r: The machine produces dango with colors \(l, l+1, \ldots, r\). These dango are pushed sequentially onto the stack (i.e. first \(l\), then \(l+1\), and so on until \(r\)).
- 2 k: A customer wants to purchase \(k\) dango. Qinglan will pop \(k\) dango from the top of the stack one by one and sell them. It is guaranteed that \(k\) does not exceed the current number of dango in the stack.
Your task is to output the total selling price for each operation of type 2. The price of a dango is equal to its color value.
inputFormat
The first line contains an integer \(n\) (the number of operations). Each of the following \(n\) lines describes an operation. An operation is in one of the following formats:
- 1 l r — Production operation. \(l\) and \(r\) are integers with \(l \leq r\), and dango with colors \(l, l+1, \ldots, r\) are produced.
- 2 k — Sales operation. \(k\) is an integer, and it is guaranteed that \(k\) is at most the current number of dango in the stack.
outputFormat
For each operation of type 2, output a single line containing the total price of the dango sold in that operation.
sample
4
1 1 3
2 2
1 2 4
2 3
5
9
</p>