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


How to do range update and range query simultaneously?

I need a way to find solve this :

Given array, use one of two operations. add k to all elements in a given interval, find sum of values in a given interval (both range update and range query simultaneously). I know how to do it using Fenwick tree data structure. I need it using segment tree. Can any one please provide a link to a tutorial?

in reference to the problem :

Can it be done without lazy propagation?

p.s. I found this simple solution Can anyone explain it a bit please? I am confused with two variables in the segment tree. Please help

asked 14 Aug '15, 12:07

dragonemperor's gravatar image

accept rate: 10%

edited 14 Aug '15, 16:10

use the above link for the basic idea about the segment trees useful for range queries and the next link for lazy propagation in the segment trees which is useful for the range updates.


answered 14 Aug '15, 12:44

vjvishjn's gravatar image

accept rate: 0%

Hey, can this be done without lazy propagation? I am not worried about strict time limit.

(14 Aug '15, 13:07) dragonemperor3★

Hi dragonemperor,

if you are not worried about time limit then :

all type of problem which are solved by lazy propagation can be definitely solve by segment tree because lazy propagation concept is introduced due to high time complexity of segment tree so your update will take O(n) and query take O(long(n)) because updating tree is like updating array you have to update all children + parent node within that range means you have to update each single element within range as you do update in binary search tree and store sum in parent node i.e it will not make any sense :(


answered 14 Aug '15, 23:10

admin123's gravatar image

accept rate: 28%

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: 14 Aug '15, 12:07

question was seen: 2,650 times

last updated: 14 Aug '15, 23:10