Speed optimizations (logarithmic search via std::lower/upper_bound())