← Back to topics
Topic

z-trees

1
1010011010
There is a system error in this task. Can anyone fix it?
m
matteo123
Can you explain the idea to solve this task.
s
syntax_error
Well the test cases are missing, nobody ever fixes them here.. Why even bother solving the problem? :(
Anyway, the solution converts the problem into a system of difference constraints, which can be solved using bellman ford. The trick that makes it solvable is to look at prefix-sums ( for example, let p[x] equal the number of trees from <-inf, x] ). Then if there are 5 trees in [x, y], you can say p[y]-p[x-1] = 5... and so on...