#C4277. Problem Management in a Coding Competition

    ID: 47797 Type: Default 1000ms 256MiB

Problem Management in a Coding Competition

Problem Management in a Coding Competition

You are tasked with managing the problems in a coding competition. Initially, there are P problems, each defined by an ID and a point value. You will then process a series of O operations. The operations are of three types:

  • ADD ID POINTS: Add a new problem with the given ID and POINTS or update the points if the problem already exists.
  • REMOVE ID: Remove the problem with the given ID.
  • TOTAL L R: Calculate the sum of points for all problems with IDs in the inclusive range from L to R. For each TOTAL operation, output the sum on a new line.

The input will be read from standard input (stdin) and the output should be written to standard output (stdout).

The formula to compute the sum for a TOTAL operation can be expressed in LaTeX as:

\( \text{SUM} = \sum_{i \in \{ ID \mid L \leq ID \leq R \}} \text{points}_i \)

inputFormat

The first line contains two space-separated integers P and O, where P is the number of initial problems and O is the number of operations.

The next P lines each contain two integers: ID and POINTS, representing a problem's ID and its point value.

The following O lines each contain an operation in one of the following forms: "ADD ID POINTS", "REMOVE ID", or "TOTAL L R".

outputFormat

For each "TOTAL L R" operation, output a single line with the sum of the points for the problems with IDs in the inclusive range from L to R.

## sample
3 4
1 10
2 20
3 30
TOTAL 1 2
ADD 4 40
REMOVE 2
TOTAL 1 4
30

80

</p>