#C5812. Sum of Numbers

    ID: 49503 Type: Default 1000ms 256MiB

Sum of Numbers

Sum of Numbers

You are given a data structure that supports two operations: add and getSum. The data structure initially starts empty. There are two types of operations:

  1. Operation 1 (add): Add an integer to the end of the list.
  2. Operation 2 (getSum): Given an integer k, output the sum of the last k numbers added to the list.

It is guaranteed that when a getSum operation is performed, there are at least k numbers in the list.

Your task is to process a series of queries and for each getSum query, output the sum of the last k numbers. Note that all formulas in the problem statement are in LaTeX format; for instance, the condition for a valid getSum query is (\text{size of list} \ge k).

inputFormat

The input begins with a single integer (Q) ((1 \le Q \le 10^5)), the number of queries. Each of the next (Q) lines represents a query in one of the following formats:

  • For an add operation: 1 x where (x) is the integer to add to the list.
  • For a getSum operation: 2 k where (k) denotes that you must output the sum of the last (k) numbers in the list.

It is guaranteed that each getSum query is valid (i.e. the list contains at least (k) elements).

outputFormat

For each query of type 2 (getSum), output a single integer representing the sum of the last (k) numbers in the list. Each answer should be printed on a new line.## sample

6
1 3
1 0
1 2
1 5
1 4
2 2
9

</p>