Technique
Persistent Segment Tree
On each update copy only the O(log n) changed nodes, keeping every past version queryable.
Learn firstSegment Tree / Fenwick (BIT)
0%
mastery
0/1 solved
0/1 solved
Recognise it
The signal
queries on historical versions
1Brute force
Copy the whole array per version.
2The observation
Full copies: unchanged subtrees are shared.
3Why it works
Version t's root sees exactly the state after the first t updates.
Reach for it when
- +k-th smallest in a subarray (versions over prefixes)
- +copy-and-modify arrays
Not when
- ×offline answers suffice (sort queries and use a normal BIT)
Practice
0/1 solved
- Range Queries and CopiesCSESHard
Pitfalls
Misconceptions
- !memory blow-up from allocating children with new in tight limits