You are not logged in. Please login at www.codechef.com to post your questions!

×

Range update and query on a non-standard array

I have an array arr[] of size n (<=10^5) and I have to do range update and query over it.

Problem is, the update has to happen according to an update multiplier array mult[]={c_0,c_1,c_2, ...} such that if I add k on arr[a] to arr[b], then

arr[a] = arr[a]+k*c_a
arr[a+1] = arr[a+1] + k*c_(a+1)
.
.
.
arr[b] = arr[b] + k*c_b

I have to do lazy update. What will the update function be like?

asked 08 Dec '15, 01:16

akash_goel23's gravatar image

2★akash_goel23
12613
accept rate: 20%


in each segtree node keep 3 variables
Sum_Of_Arr
Lazy
Sum_Of_Mult

while updating , if current node is completely inside the update range just do lazy += k , while doing the push() operation in segtree , do sum_of_arr += lazy * sum_of_mult , and propogate lazy to the children.

link

answered 08 Dec '15, 12:52

rajat1603's gravatar image

7★rajat1603
1.0k112
accept rate: 4%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,502
×126

question asked: 08 Dec '15, 01:16

question was seen: 942 times

last updated: 08 Dec '15, 12:52