export declare class SegmentTree { private readonly _tree; private readonly _origSize; private readonly _builder; /** * Initializes the segment tree. * @param nums - Array of numbers to query from. * @param builder - A custom function to build the tree (e.g. sum, min, max). * * @timeComplexity `O(n)` * * @example * // For sum queries * let st = new SegmentTree([1, 2, 3]); * st.query(0, 1); // 3 * * // For max queries * let st = new SegmentTree([1, 2, 3], (a, b) => Math.max(a, b)); * st.query(0, 1, -Infinity); // 2 * * // For min queries * let st = new SegmentTree([1, 2, 3], (a, b) => Math.min(a, b)); * st.query(0, 1, Infinity); // 1 */ constructor(nums: number[], builder?: SegmentTreeBuilder); /** * Queries the tree for a combined value over a range. * * @param start The starting index of the range (inclusive). * @param end The ending index of the range (inclusive). * @param resultInitialValue The initial value to * start combining with. (Defaults to `0`). * * @timeComplexity `O(log(n))` * * The choice of this value should depend on the builder function: * - When querying for sum, set this to `0`. (Default) * - When querying for maximum value, set this to `-Infinity`. * - When querying for minimum value, set this to `Infinity`. * - For other operations, use an appropriate initial value * that aligns with the builder function. * @returns The result of the query over the range. */ query(start: number, end: number, resultInitialValue?: number): number; /** * Updates the value at a specific index. * * @param index The index of the value to update. * @param newValue The new value. * * @timeComplexity `O(log(n))` */ update(index: number, newValue: number | ((num: number) => number)): void; } export type SegmentTreeBuilder = (a: number, b: number) => number;