EDIT : I know the basic SQRT Techniique just the range update part as when we update it block by block, the next query which requires us to traverse each element(all in 1 block) then what happens?
Thanks
The exact idea depends on the problem, but the general idea is like this. Suppose you want to update a range [l, r]. You start from l and move to the right until you reach the end of the block. Then, you jump from block to block until you reach the block containing r. Finally, you move from your current position to r. This way, you travelled O(\sqrt{n}) times.
You can study from here https://blog.anudeep2011.com/mos-algorithm/
But I donât think you can apply that in the problem that you have mentioned (correct me if Iâm wrong),I think Sqrt Decomposition works only if the queries are independent i.e. one query doesnât affect the result of the other, and the order in which the queries are answered doesnât matter, which is generally not the case in problems involving update queries. Sqrt Decomposition is just an ordering of the queries to be answered, so that the complexity is reduced. Youâll realize this once youâre done studying the technique.
thatâs Nice you learned, now can you please explain to me why the max size of the block was chosen to be 20?
or
In general how do we choose the max size?
I think the method presented by zscoder is wrong. When you update âlâ to ârâ you cant jump from block to block because you have to update original array by the new value from âlâ to ârâ otherwise future queries will give wrong answers. In point update also we update the original array by the ânew valueâ. So by this correct method range update will have O(n) and not O(sqrt n). Am I wrong ? and is there some other optimized way of range updates in sqrt decomp. ?