Binary Lifting and Lowest Common Ancestor
Introduction
Given an integer array of size n.
There are m queries, each query consists of two integers x and y, asking for the maximum value in the range [x, y] of the array.
Approach
A straightforward method would be to precompute f[i][j] representing the maximum value from index i to j. However, this approach is inefficient.
Instead, we can ...
Posted on Fri, 03 Jul 2026 16:49:36 +0000 by Gighalen
Competitive Programming Template Collection
Tarjan's Algorithm for Strongly Connnected Components
namespace TarjanSCC {
int dfn[N], low[N], index, colorCount;
int comp[N], size[N], value[N];
bool inStack[N];
stack<int> stk;
vector<int> graph[N];
void tarjan(int u) {
dfn[u] = low[u] = ++index;
stk.push(u);
inStack[u] = true;
...
Posted on Tue, 02 Jun 2026 18:01:50 +0000 by justgrafx