#K68527. Network Traffic Queries

    ID: 32884 Type: Default 1000ms 256MiB

Network Traffic Queries

Network Traffic Queries

You are given a series of commands to simulate network traffic data processing. There are two types of commands:

  • A t s: Add a data packet with size s at timestamp t.
  • Q l r: Query the total size of packets with timestamps in the range \(l \leq t \leq r\).

For a sequence of commands, process them in order. For each query command, output the sum of sizes of all packets whose timestamps lie in the given interval.

The sum for a query can be expressed as \(S = \sum_{t=l}^{r} packet(t)\), where packet(t) is the sum of sizes recorded at timestamp \(t\). If no packet exists at a certain timestamp within the range, it contributes 0 to the sum.

inputFormat

Input is read from standard input (stdin). The first line contains an integer \(n\) denoting the number of commands. Each of the following \(n\) lines contains a command in one of the following formats:

  • A t s: Add a packet at timestamp t with size s.
  • Q l r: Query the sum of sizes for timestamps between l and r (inclusive).

outputFormat

For each query command, output the result (i.e. the computed sum) on a separate line to standard output (stdout).

## sample
5
A 100 200
A 150 300
Q 100 200
A 200 400
Q 100 250
500

900

</p>