Блог пользователя 123gjweq2

Автор 123gjweq2, 2 года назад, По-английски

I was reading this: https://cp-algorithms.com/data_structures/segment_tree.html (segment tree) and I noticed something crazy. The create function is unnecessary. You can just call $$$n$$$ update functions. This could actually save 1-2 minutes of typing. Maybe even 10-20 minutes if the segment tree is especially weird.

Edit: okay, I see how this is not optimal. It looks like this would have a time complexity of $$$O(n \cdot log(n))$$$, while the normal creation method has a time complexity of $$$O(n)$$$.

  • Проголосовать: нравится
  • -32
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

The build function takes less than a minute to code, wtf are you on about

»
2 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

also the time complexity might be the same but the constant factor for calling update N times will be way larger, since we'll be recursively going through a segment multiple times (with some being returned early)

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

You should use a build function. This could actually save 0.1s-1s of execution. (However this is nothing compared to your 1-2 minutes)