The problem can be solved using segment trees. Every node of the tree stores the following data :
tree0[k] : In the range [low…high] covered by this node, how many numbers are divisible by 3 considering just additions performed on numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2
tree1[k] : In the range [low…high] covered by this node, how many numbers leave a remainder of 1 when divided by 3 considering just additions performed on numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2
add[k] : What is the quantity which is added to all numbers totally inside this range and not considering additions performed on ranges which are a subrange of the range covered at node k/2
plz elaborate your explaination…its too difficult too understand from such 3 confusing statements u have mentioned just for the sake of editorial… - _ -
How can one identify that this should be solved through segment tree ?
are there any ways to identify such problems (related to segment etc) ?
also is there any other way to solve this ?
@piyusjain1555 its a question of “lazy propagation” in “segment tree”… looks like you were a beginner for coding… so you can google and learn how to do this type of questions… u have have a look at FLIPCOIN which is similar to this question…