Given a tree and queries, each asking for the LCA of two nodes and .
Using Euler tour + Sparse Table:
- Preprocess:
- Each query:
Alternative: Binary lifting gives preprocess, query.
Better for smaller , worse for large . Constraints: up to , up to .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
O(1) LCA with preprocessing
Given a tree and queries, each asking for the LCA of two nodes and .
Using Euler tour + Sparse Table:
Alternative: Binary lifting gives preprocess, query.
Better for smaller , worse for large . Constraints: up to , up to .