idek_bro's blog

By idek_bro, history, 2 years ago, In English

Does a segment tree provide any functionality other than storing the sums of sub arrays? Is the usage of unordered_sets to store the sums of subarrays from [0,0] to [0,n], to calculate the sum of the subarray [l,r] as [0,r]-[0,l-1] a valid alternative to segment trees?

  • Vote: I like it
  • +10
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

Segment Trees also allow you to update values in $$$O(logN)$$$ time. Using Prefix Sums would not allow you to update values in $$$O(logN)$$$ time, because in the worst case, you'd need to change all $$$O(N)$$$ prefix sums (which happens when the first element in the array is changed).

»
2 years ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

There is no such easy thing like prefix sums that can be used for finding minimum on segment. And the segment tree is one of the most easy and effective ways to do this. It also allows you to do tons of crazy stuff. For example, adding Fibonacci sequence on segment and then calculating sum on segment.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Segment tree can store monoids

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why are you learning segment trees after you do 2 codeforces problems