whoashish's cp notes

Home

❯

8. Range Queries

8. Range Queries

Oct 08, 20262 min read

  • i. Sparse Table: O(1) queries on a static array after O(nlogn) preprocessing.
  • ii. Range Minimum Query: RMQ on a static array is equivalent to LCA on a tree:
  • iii. Fenwick Tree: A Fenwick tree (binary indexed tree) stores partial sums over power-of-two blocks:
  • iv. Segment Tree: A segment tree stores an associative aggregate for each of the O(n) canonical segments.
  • v. Lazy Propagation: Range updates in O(logn):
  • vi. Dynamic and Persistent Segment Trees: struct DynSeg {
  • vii. Segment Tree Beats and Historic Values: Some updates can’t be applied to a whole node in O(1):
  • viii. Li Chao and Kinetic Segment Trees: Both maintain sets of lines and answer “best value at x”.
  • ix. Segment Tree Merging and Splitting: Many dynamic segment trees over the same value range [0,n) share one node pool.
  • x. Range Order Statistics and Wavelets: Queries like “k-th smallest in a[l..r)”, “how many values in [x,y) lie in a[l..r)”, predecessor/successor within a range.
  • xi. Sqrt Decomposition: Split something (the array, the values, the time line, the set of objects) into  ​-sized pieces so that two different costs balance.
  • xii. Mo’s Algorithm: Offline range queries where the window [L,R) can be extended and shrunk by one element in O(1) (or O(log)):
  • xiii. Offline and 2D Range Queries: Most “2D” problems (points in rectangles, range queries with a value condition, distinct values in a range) become 1D after sorting by one coordinate and sweeping with a Fenwick tree over the other.
  • xiv. Permutation Tree: For a permutation p, call a subarray p[l..r) an interval if its values form a contiguous range, i.e.
  • xv. Range LIS: Answer “length of the longest strictly increasing subsequence of a[l..r)” for many ranges.

15 items under this folder.

  • Oct 08, 2026

    i. Sparse Table

    • range-queries
    • sparse-table
  • Oct 08, 2026

    ii. Range Minimum Query

    • range-queries
    • rmq
    • lca
  • Oct 08, 2026

    iii. Fenwick Tree

    • range-queries
    • fenwick
  • Oct 08, 2026

    iv. Segment Tree

    • range-queries
    • segment-tree
  • Oct 08, 2026

    v. Lazy Propagation

    • range-queries
    • segment-tree
    • lazy
  • Oct 08, 2026

    vi. Dynamic and Persistent Segment Trees

    • range-queries
    • segment-tree
    • persistence
  • Oct 08, 2026

    vii. Segment Tree Beats and Historic Values

    • range-queries
    • segment-tree-beats
  • Oct 08, 2026

    viii. Li Chao and Kinetic Segment Trees

    • range-queries
    • li-chao
    • convex-hull-trick
  • Oct 08, 2026

    ix. Segment Tree Merging and Splitting

    • range-queries
    • segment-tree
    • merging
  • Oct 08, 2026

    x. Range Order Statistics and Wavelets

    • range-queries
    • order-statistics
    • wavelet
  • Oct 08, 2026

    xi. Sqrt Decomposition

    • range-queries
    • sqrt
  • Oct 08, 2026

    xii. Mo's Algorithm

    • range-queries
    • mo
    • offline
    • sqrt
  • Oct 08, 2026

    xiii. Offline and 2D Range Queries

    • range-queries
    • offline
    • 2d
    • sweep-line
  • Oct 08, 2026

    xiv. Permutation Tree

    • range-queries
    • permutation
    • divide-and-conquer
  • Oct 08, 2026

    xv. Range LIS

    • range-queries
    • lis
    • monge
    • seaweed