ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1855. Trade Guilds of Erathia

Can't understand the problem
Posted by Skeef79 11 Sep 2019 18:29
How is it possible??
Establish 2 4 = 2.6667?

1 2 3 4
1 2 2

(2+2)/2 = 2
Re: Can't understand the problem
Posted by Gilles Deleuze 11 Sep 2019 20:02
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
Re: Can't understand the problem
Posted by Skeef79 12 Sep 2019 13:51
Thank you!