Gamified challenge · Segment trees
scores[i] is the score in lane i. Then ops arrive in order, each a string: "set i v" changes lane i's score to v (scores can be negative), and "sum l r" asks for the total of lanes l to r, both included (0-based, l ≤ r).
Write process(scores, ops) that returns the answers to the sum operations, in order (an empty list if there are none). There can be hundreds of lanes and operations, so aim for O(log n) per operation with a segment tree or a Fenwick tree.
Example: scores = [5, 3, 8, 6, 1, 4], ops = ["sum 1 3", "set 2 0", "sum 0 5"] → [17, 19].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google