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

Автор pH7, история, 6 лет назад, По-английски

Hi all! I was wondering about solution if in Spoj HORRIBLE we are required to get range multiplication instead of range sum. So basically how can we solve below problem ?

Given an array of N elements handle below two type of range queries. - Update L R v : Add v to each element in range [L, R] - Query L R : Get multiplication of each element in range [L, R]

I am out of ideas. Please help!

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

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

Auto comment: topic has been updated by pH7 (previous revision, new revision, compare).

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

Use a segment tree: Segment tree — cp-algorithms

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

Where do you see a multiplication there? "...which is the sum of all the..."

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

Can we even handle updates with segment tree?

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

Similar to a problem in the ongoing Long challenge. I hope this is just a coincidence.

WEIRDMUL

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

If you want to have multiplication instead of sum, think of replacing each $$$x$$$ in the array with some $$$f(x)$$$, such that $$$f(xy) = f(x) + f(y)$$$. Then, by calculating sum of $$$f(x_i)$$$ in some range, you will in fact calculate $$$f(\Pi{x_i})$$$ in the range. But the addition to the range in this case would not be possible -- instead, such problem would probably require multiplication of all numbers in the range by some v.