Graph Theory37 sections · 1633 units
Open in Course

Complexity Summary

(Preprocessing and queries)

Preprocessing: O(nlog⁡n)O(n \log n) time, O(nlog⁡n)O(n \log n) space. You build the sparse table once. Queries: O(log⁡k)O(\log k) per query, where kk is the jump distance. In the worst case, k=nk = n, so queries take O(log⁡n)O(\log n). If you have qq queries, total time is O(nlog⁡n+qlog⁡n)O(n \log n + q \log n). For n=100,000n = 100,000 and q=1,000,000q = 1,000,000, that is under 2020 million operations.

This is fast enough for any competitive programming time limit.