#P4743. Contiguous Device Attribute Sum Query

    ID: 17987 Type: Default 1000ms 256MiB

Contiguous Device Attribute Sum Query

Contiguous Device Attribute Sum Query

During the kite festival, ( Curtis\ Nishikino ) arrives at the energy center where preparations are underway for the evening party. Initially, there are ( N ) devices, each having ( M ) attributes numbered from ( 0 ) to ( M-1 ). For device ( i ) and its ( j )th attribute, the given value is denoted by ( value_{ij} ). If a device does not explicitly have an attribute, its value is considered ( 0 ). Due to schedule adjustments, devices may be added or removed dynamically (with the total number never exceeding ( 10^4 )). Volunteers are tasked with forming a contiguous block of devices. For a chosen block from index ( l ) to ( r ), the final effect for attribute ( i ) is computed as [ S_i = \sum_{p=l}^{r} value_{pi}, \quad \text{for } i=0,1,\ldots,M-1. ] Your task is to process a sequence of operations and for each query, compute and output these sums.

inputFormat

The input begins with a line containing three integers ( N ), ( M ), and ( Q ), where:

  • ( N ) is the initial number of devices,
  • ( M ) is the number of attributes per device, and
  • ( Q ) is the number of subsequent operations.

Each of the next ( N ) lines contains ( M ) integers, representing the attribute values of a device.

Following that, there are ( Q ) lines describing operations. Each operation is one of the following:

  1. Query Operation: Q l r
    Query the contiguous block from index ( l ) to ( r ) (inclusive, 0-indexed) and output the sum for each attribute.

  2. Add Operation: A x_0 x_1 ... x_{M-1}
    Append a new device with the given ( M ) attribute values to the end of the list.

  3. Remove Operation: R
    Remove the last device from the list. It is guaranteed that removal operations will only be executed when there is at least one device.

outputFormat

For each query operation (Q l r), output a single line containing ( M ) integers. These integers represent the sum of each attribute for the devices in the range [( l ), ( r )] and should be separated by spaces.

sample

3 2 5
1 2
3 4
0 5
Q 0 2
A 2 2
Q 1 3
R
Q 0 1
4 11

5 11 4 6

</p>