You are not logged in. Please login at 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

accept rate: 20%

in each segtree node keep 3 variables

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.


answered 08 Dec '15, 12:52

rajat1603's gravatar image

accept rate: 4%

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 08 Dec '15, 01:16

question was seen: 917 times

last updated: 08 Dec '15, 12:52