Segment Tree Range Sum

Programming Interview Hard 5 views
Back to Questions

Problem Description

Given {x}, Two types: 1 i x means set a[i]=x, 2 l r means output sum of a[l..r] (1-based). Implement build/update/query helpers.

Input Format

First line n q. Second line n integers. Next q lines queries.

Output Format

For type 2 print sums.

Sample Test Case

Input:
5 5 1 2 3 4 5 2 1 3 1 2 10 2 2 5 1 5 -1 2 1 5
Output:
6 22 17

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next