Heavy-Light Decomposition Template for Tree Path Queries

The following C++ implementation demonstrates a complete Heavy-Light Decomposition (HLD) framework integrated with a lazy propagation segment tree to support efficient path updates and queries on trees. It passes the standard template problem on Luogu. #include <bits/stdc++.h> using namespace std; using i64 = long long; int MOD; struct ...

Posted on Mon, 18 May 2026 00:02:42 +0000 by swizzer

Introduction to Segment Trees and Range Queries

Range Extremum Queries and Algorithmic ChoicesRange Maximum/Minimum Query (RMQ) problems involve processing an array of size n to handle multiple range queries and bulk modifications. Different data structures offer varying trade-offs:Brute Force: Simple implementation suitable for small datasets, but query performance is poor.Binary Indexed Tr ...

Posted on Wed, 13 May 2026 21:56:16 +0000 by Niruth

Segment Tree Historical Values and Advanced Tagging Techniques

Maintaining Range Minimum and Historical MaximumWhen a segment tree needs to support range addition, range minimum assignment, range sum, range maximum, and range historical maximum, a standard approach involves tracking the maximum value, strict second maximum value, and the count of maximum values within each node. Operations affecting the mi ...

Posted on Tue, 12 May 2026 19:45:03 +0000 by Pazuzu156