Binary Lifting for LCA Queries
Directory
Preprocessing
LCA
External Function Version
Preprocessing
void solve() {
int n, k;
cin >> n >> k;
vector<vector<int>> adj(n + 1);
for (int i = 1; i <= n - 1; ++i) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
vecto ...
Posted on Tue, 08 Sep 2026 16:35:03 +0000 by FadeOut79
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