#K42777. Warehouse Operations

    ID: 27163 Type: Default 1000ms 256MiB

Warehouse Operations

Warehouse Operations

You are given a warehouse with n bins, each capable of holding at most \(m\) items. You have to perform \(q\) operations on these bins. The operations are of three types:

  • 1 i x: Add \(x\) items to bin \(i\). However, the number of items in bin \(i\) cannot exceed \(m\) (i.e. after the operation, the number of items becomes \(\min(\text{current} + x,\, m)\)).
  • 2 i x: Remove \(x\) items from bin \(i\). The number of items cannot drop below 0 (i.e. after the operation, the number becomes \(\max(\text{current} - x,\, 0)\)).
  • 3 i j: Query the total number of items in bins \(i\) through \(j\) (inclusive). Print the sum for this query.

The bins are numbered from 1 to \(n\). You are to read the operations from standard input and output the result of each query operation, each on a new line.

inputFormat

The first line of input contains three space-separated integers: \(n\) (the number of bins), \(m\) (the maximum capacity for each bin), and \(q\) (the total number of operations).

The following \(q\) lines each describe one operation in one of the formats:

  • "1 i x" — add \(x\) items to bin \(i\).
  • "2 i x" — remove \(x\) items from bin \(i\).
  • "3 i j" — output the sum of items from bin \(i\) to bin \(j\) (inclusive).

outputFormat

For each query operation (type 3), output the sum of items in the specified range on a new line.

## sample
5 100 6
1 2 50
1 3 60
3 1 3
2 3 30
3 1 3
3 3 5
110

80 30

</p>