Implementation of segment trees