#K6641. Card Ordering System
Card Ordering System
Card Ordering System
You are required to implement a card ordering system that supports two kinds of operations: adding cards to a client's order and querying the total number of cards ordered within a specific range. The system is initialized with an array of orders where each element represents the number of cards ordered by a client.
Let the initial orders be \(a_1, a_2, \dots, a_n\). We define the prefix sum array \(P\) as follows:
[ P[0]=0,\quad P[i]=\sum_{k=1}^{i}a_k,\quad 1\le i\le n. ]
A range query for clients in the interval \([L, R]\) (1-indexed) should return:
[ \text{result} = P[R] - P[L-1]. ]
Your task is to process a sequence of \(q\) operations. Each operation is one of the following:
- Add Operation: "1 client_index num_cards" — Increase the number of cards for the client at position client_index by num_cards.
- Query Operation: "2 left_index right_index" — Output the sum of cards ordered by clients between indices left_index and right_index (inclusive).
Input and output are both via standard streams.
inputFormat
The input begins with a line containing two integers \(n\) and \(q\), where \(n\) is the number of clients and \(q\) is the number of operations.
The next line contains \(n\) space-separated integers representing the initial orders of the clients.
Each of the following \(q\) lines represents an operation in one of the following formats:
1 client_index num_cards
— Add num_cards to the order of the client at index client_index (1-indexed).2 left_index right_index
— Query the total number of cards ordered by clients in the range [left_index, right_index].
outputFormat
For each query operation (type 2), output the resulting sum on a new line using standard output.
## sample5 3
10 20 30 40 50
2 2 4
1 3 10
2 1 5
90
160
</p>