Data Structures19 sections · 729 units
Open in Course

Block Decomposition for Updates

Range updates too

So far you've seen point updates. What about range updates? For "add vv to all elements in [l,r][l, r]", use lazy blocks:

1.1. For complete blocks in [l,r][l, r]: add vv to a blockAddblockAdd array

2.2. For partial blocks (tails): update individual elements Queries now add blockAdd[block]blockAdd[block] to each accessed element. You get O(n)O(\sqrt{n}) for both range updates and point queries. The technique is called "sqrt decomposition with lazy propagation."