Re: Can't understand the problem

I don't understand what you mean there.

In fact, the problem asks for an interval [l, r] to find the average cost of a sub-interval.

That is, as for the first test case. After two 'change' queries we have cost(1, 2) = 1; cost(2, 3) = 2, cost(3, 4) = 2. Then we are asked for the average on the interval [2, 4] which is (cost(2, 3) + cost(3, 4) + cost(2, 4)) / 3.

So, given an interval [l, r] you are asked to compute:

int64_t n_of_intervals = 0;

int64_t total_sum = 0;

for (int i = l; i < r; ++i)

for (int j = i + 1; j <= r; ++j)

n_of_intervals += 1

total_sum += cost(i, j)

output total_sum / n_of_intervals