Segment Tree Techniques: From Basic Templates to Advanced Competitive Programming Problems
Basic Segment Tree with Lazy Propagation
The fundamental segment tree template maintains range sum with lazy propagation for range addition operations.
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
struct SegNode {
int left, right;
int64 sum;
int64 lazy;
};
class SegmentTree {
private:
static con ...
Posted on Sat, 27 Jun 2026 16:07:29 +0000 by oshecho
Competitive Programming Contest Solutions: Segment Trees and Combinatorial Optimization
Problem 1: Maximum Goals and Assists
Problem Overview
Given two arrays representing goals and assists for multiple players, process queries that ask for the maximum total balls needed under different matching scenarios.
Key Observations
The problem essentially asks for the maximum value among three distinct scenarios:
Scenario 1: Each assist ca ...
Posted on Sun, 24 May 2026 16:31:07 +0000 by KingIsulgard
Segment Tree Template for Competitive Programming: Point Updates and Range Queries
The following reusable segment tree implementation uses 0-based indexing with half-open intervals [l, r). It supports point assignment, point addition, range queries, and methods to locate the first or last endex satisfying a custom predicate.
#include <bits/stdc++.h>
template<typename Info>
struct SegmentTree {
int size = 0;
...
Posted on Thu, 07 May 2026 09:24:23 +0000 by ainoy31