#K73637. Fenwick Tree Operations
Fenwick Tree Operations
Fenwick Tree Operations
You are given an initially zero-filled array of size \(n\) and a series of operations. There are two types of operations:
- Update Operation: "U i v" sets the element at index \(i\) to value \(v\).
- Query Operation: "Q l r" calculates the sum of the elements from index \(l\) to \(r\) (inclusive).
Your task is to implement these operations efficiently using a Fenwick Tree (Binary Indexed Tree). The Fenwick Tree allows both update and query operations in \(O(\log n)\) time.
Note: In the input, indexing is assumed to start at 1.
inputFormat
The input is given via stdin in the following format:
n t operation_1 operation_2 ... operation_t
Here, \(n\) is the size of the array, \(t\) is the number of operations, and each operation is either:
U i v
: Update the element at index \(i\) to value \(v\).Q l r
: Query the sum of the elements from index \(l\) to \(r\) (inclusive).
outputFormat
For each query operation, output the result on a new line via stdout.
## sample5
4
U 1 10
U 2 5
Q 1 2
Q 1 5
15
15
</p>