|
|
|
|
|
by knuthsat
1926 days ago
|
|
Any dynamic programming algorithm where n-th item depends on contiguous k ones with some nice binary operation (like +) can benefit from storing the state in a segment tree, so when you go and calculate n-th item, you can get the value in log(n) instead of O(k) (although prefix sums work fine there too if + is involved). I know also of examples where lazy segment tree is used too. Segment trees can also be used to decode the kth lexicographic permutation of a sequence of elements in O(n log n) instead of O(n ^ 2). Here's one variant of the above application: https://www.spoj.com/problems/QUE2/ |
|
The only way I can currently envision a segment tree being used for a problem like that is grouping elements every k to provide a faster lookup.
Like, these k elements have a value < x, the next k elements have a value < y, etc.