Given an array of N 32-bit floating point values and an integer array
flags of the same length, where flags[i] = 1 marks the start of a new
segment and flags[i] = 0 continues the current segment, compute the
exclusive prefix sum within each segment and store the result in
output. The first element is always a segment start
(flags[0] = 1). Within each segment, output[i] equals the sum of all
values elements in the same segment that appear before index i, so the
first element of every segment is always 0.0.
solve function signature must remain unchangedoutputvalues and flags; write to outputInput values: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] Input flags: [ 1, 0, 0, 1, 0, 1] Segments: [1.0, 2.0, 3.0] | [4.0, 5.0] | [6.0] Output: [0.0, 1.0, 3.0, 0.0, 4.0, 0.0]
Segment 1: exclusive prefix sums of [1, 2, 3] → [0, 1, 3]
Segment 2: exclusive prefix sums of [4, 5] → [0, 4]
Segment 3: exclusive prefix sums of [6] → [0]
N ≤ 100,000,000flags[0] = 1 always (the first element starts the first segment)flags[i] ∈ {0, 1} for all iN = 50,000,000