Technique
Lazy Propagation Segment Tree
Store pending range updates at nodes and push them down only when a child is visited, so range assign/add + range query is O(log n).
Learn firstSegment Tree / Fenwick (BIT)UnlocksTreap / Implicit Treap
0%
mastery
0/8 solved
0/8 solved
Recognise it
The signal
range add/assign plus range sum/min
1Brute force
Point-update every element in the range: O(n) per update.
2The observation
Per-element range updates: a fully covered node absorbs the update as a tag.
3Why it works
Each node's value is correct given all tags on its ancestors have been applied.
Reach for it when
- +interval painting with queries
- +toggle ranges
Not when
- ×only point queries after range adds (Fenwick with diff-array)
- ×updates that do not compose (segment tree beats or sqrt)
Practice
0/8 solved
- Range Updates and SumsCSESMedium
- NaginiCodeforces3100
- StationsCodeforces3400
- Bear and Bad Powers of 42Codeforces3100
- Polynomial QueriesCSESHard
- Physical Education LessonsCodeforces2300
- A Simple TaskCodeforces2300
- Please, another Queries on Array?Codeforces2400
Pitfalls
Misconceptions
- !wrong order of composing assign and add tags