I would like to solve Joseph Flavius problem using segment tree. I'm almost sure that simple simulation (i.e. lined list) is O(n^2)
. What I want to achieve is jumping on array for particular distance, taken from segment tree. In other words segment tree will keep information about number of deleted elements and taking some info from tree will allow to find next element to delete in O(1). The problem is that I dont know how to storage info in segment tree to make it working for Joseph Flavius problem.
Some kind of extra values keeped in each node? But how to make queries about next element?