Manuscript Offprint
arXiv:2610.20983Near-Linear Preprocessing for Range Weighted Longest Increasing Subsequence Queries
Abstract
We give a deterministic data structure for range weighted longest increasing subsequence (LIS) queries on values with positive weights. Preprocessing takes time and space. Value queries take time, and an optimal subsequence of elements can be reported in time. This resolves an open question on truly subquadratic preprocessing with polylogarithmic query time. The key is a single-crossing property of envelopes for value-separated endpoint sets, enabling -time persistent merges. The bounds assume constant-time exact addition and comparison of weights.
1 Introduction
Let be a sequence with positive real weights . A range weighted longest increasing subsequence query asks for the maximum total weight of a strictly increasing subsequence in an index interval . A reporting query also returns an optimal subsequence.
For unweighted range LIS, Tiskin’s semi-local comparison techniques give preprocessing and time to return the length [Tis15]; see also the formulation in [GGK25, Lemma B.14]. Gawrychowski, Gorbachev, and Kociumaka [GGK25, Theorem 1.3] support reporting in time after preprocessing, for every . Here is the output length. Their construction uses core-sparse Monge matrix multiplication, where the core records nonzero mixed second differences. The theorem and appendix numbers cited from [GGK25] refer to its full version.
For arbitrary positive weights, Gawrychowski et al. [GGK25, Appendix B.1] ask whether truly subquadratic preprocessing and polylogarithmic query time are possible. Their alignment-matrix construction remains correct, but the unweighted core-size guarantee no longer follows from their analysis. Karthik C. S. and Rahul [KR26, Section 7 of the full version] also ask for a truly subquadratic algorithm for weighted one-dimensional range LIS.
Theorem 1.1. There is a deterministic data structure for range weighted LIS with preprocessing time and space, value-query time, and reporting time.
The query intervals need not be known during preprocessing. The algorithm is exact, and its time and space bounds are independent of the weight magnitudes. We count exact additions and comparisons of weights, comparisons of input values, and operations on -bit indices and pointers at unit cost. Space counts real-weight cells and integer words.
Table 1: Selected time bounds for static range LIS. The value and reporting structures of [GGK25] can be combined within the stated preprocessing bounds. A dash indicates that no reporting bound is stated in the cited publication.
| Result | Weights | Preprocessing | Value query | Reporting |
|---|---|---|---|---|
| Tiskin [Tis15] | Unit | — | ||
| [GGK25], | Unit | |||
| [GGK25], | Unit | |||
| Theorem 1.1 | Positive real |
Unweighted specialization. Setting all weights to one gives ordinary range LIS. At the same preprocessing time, our reporting bound is , compared with in [GGK25]. Their -time reporting bound uses preprocessing. Tiskin [Tis13, Section 8.1] also states that retaining intermediate data permits output-linear traceback for semi-local LCS queries on permutations.
1.2 Overview
For each endpoint , let be the maximum weight of an increasing subsequence ending at with all indices at least , or zero if . For an endpoint set , let be the pointwise maximum of zero and its endpoint functions. The optimum for is .
The key is a single-crossing property. If all endpoint values in are smaller than those in , then holds exactly on a prefix of left boundaries. We derive this from a pairwise property using a planar path-exchange argument [Sch98, GGK25]. Consequently, consists of a prefix of and a suffix of .
We represent each envelope by a persistent segment tree indexed by . Single crossing permits -time merges with new nodes. A mutable segment tree over input values stores these roots. A value-prefix query obtains the predecessor envelope, and a persistent prefix update constructs the new endpoint function. Updating the outer tree takes further merges. Thus each element costs time and space. Saving the envelope root stored at the outer root after each input prefix reduces a range query to one point evaluation.
For reporting, persistent nodes store shared suffix witnesses represented by binary concatenations. Their weights serve as additive lazy tags. A query collects these suffixes along one tree path in time. Expanding them takes time. The construction requires no bound on Monge core size.
2 Endpoint functions
We use and for closed and half-open integer intervals. All logarithms are to base two. We may assume that is a permutation of : sort the pairs lexicographically and replace each by its zero-based rank, keeping the notation . This takes time and preserves every strictly increasing subsequence, including when input values coincide.
For , let
The maximum ranges over all lengths , including the empty subsequence of weight zero. Thus , and every nonempty interval has a positive optimum value.
For an endpoint , define to be the maximum weight of an increasing subsequence in ending at when , and set when . Each is nonincreasing on and positive exactly on .
For an endpoint set , define its envelope by
In particular, . The set E restricts only the endpoint of a subsequence. Thus,
since every nonempty feasible subsequence has an endpoint before r, whereas endpoints before l contribute zero.
The predecessor envelope for position is . The usual last-element recurrence becomes
3 Single-crossing property
We show that, when two endpoint sets are separated by value, the higher-value envelope exceeds the lower-value envelope exactly on a prefix of left boundaries. Ties favour the lower-value set. The proof uses the standard planar path-exchange argument underlying Monge inequalities [GGK25, Fact B.7].
Lemma 3.1. Let satisfy . Then there exists such that
Proof. If , any increasing subsequence ending at can be extended by . For ,
For ,
while both functions vanish for . Thus the set is .
Suppose instead that . We first show, for , that
Use the standard alignment-grid representation [Sch98, GGK25], with positive weights on the diagonal edges. Consider the directed grid on with east and north edges of weight zero. For every input position , add the diagonal edge
The resulting graph is planar: diagonals lie inside distinct unit squares and intersect grid edges only at their endpoints.
Put and . For , the diagonal edges of any path correspond to an increasing subsequence in whose values are at most . Conversely, every such subsequence determines a path of the same weight by joining its diagonal edges.
with zero-weight grid paths. If such a subsequence omits i, its indices and values are smaller than those of i. Appending i increases its weight. Hence the maximum path weight from to is exactly .
Choose maximum-weight paths from to and from to . Both lie in . The four terminals , , , are distinct and occur in this cyclic order on the boundary of the rectangle. Thus the two paths have a common vertex by planarity; see Figure 1. Swapping their suffixes at that vertex gives paths from to and from to . The sum of their weights is unchanged. Since their weights are at most and , respectively, (5) follows.
By (5), is nonincreasing on . For , . Hence the set in the lemma is a prefix of .
The pairwise property extends to value-separated endpoint sets.
Lemma 3.2. Let satisfy for all and . Then there exists such that if and only if , for every . Consequently,
Proof. Suppose . If , both envelopes remain zero for . Otherwise, choose attaining . For every ,
By Lemma 3.1, for all . Taking the maximum over and zero gives
Hence the strict comparison holds on a prefix. Choosing at equality gives (6).
4 Persistent envelope representations
We represent envelopes and their witnesses in persistent segment trees. All nodes are immutable; updates use path copying [DSST89]. Beyond persistent range updates, we only need to merge envelope pairs satisfying the single-crossing property.
4.1 Witnesses and suffix tags
A witness is an index sequence represented by an immutable handle: the empty sequence , a singleton , or a binary concatenation . We set and ; otherwise, concatenation creates one node pointing to the two nonempty handles. Each handle stores its total weight , where
Thus concatenation takes time and space, without copying or balancing the represented sequences. Binary reconstruction witnesses of this form also appear in [GGK25, Appendix B, proof of Theorem 1.3]. These operations apply to arbitrary index sequences. The feasibility of the constructed witnesses is proved in Section 5.
All function trees use the same balanced binary subdivision of . An interval of length at least two splits at . There is one leaf per coordinate, and the height

Figure 1: Two maximum-weight paths for the sequence with unit weights. Here , , , and . Horizontal and vertical edges have weight zero; diagonal edges represent selected elements.
is at most . Intervals are carried by recursive calls rather than stored in nodes. We identify a root with its represented function when no confusion arises.
A function node stores two child pointers, a suffix handle S, and the score last at its rightmost coordinate. At a leaf, it represents the pair . At an internal node, a selected child pair gives the pair
The concatenation is conceptual. Reading a node does not allocate a witness. The cache satisfies
Thus the weight of the suffix is also the additive lazy tag. Initially, we build one full tree for with empty suffixes and zero caches, in time and space. Every version retains this subdivision, including on constant intervals.
Basic operations. The operation Append(T, V) appends V at every coordinate of T. It copies the root, replaces its suffix by Cat(S, V), and increases its cache by W(V). It takes O(1) time and creates at most one function node and one witness node.
For a nonleaf root, returns its two restrictions by applying Append to each child with the parent's suffix. The order is child suffix followed by parent suffix, as in (7). Conversely, creates a parent with children , empty suffix, and cache . Both operations take time and create nodes. They leave all existing nodes unchanged.
4.2 Prefix updates
For , let append at coordinates below and leave all other coordinates unchanged. This is an ordinary persistent prefix update, given in Algorithm 1. On a fully covered interval it calls ; on an uncovered interval it returns the original root. Only the interval containing the boundary is partially covered at any level. Each level performs operations, so the update takes time and creates function and witness nodes.
Since with an empty witness for , the recurrence in (4) is realized by a single prefix update:
Algorithm 1 PrefixAppend(T, c, V) on [b, e).
1: if then return T 2: if then return Append(T, V) 3: 4: if then 5: return Join(PrefixAppend(f, c, V), g) 6: else 7: return Join(Append(f, V), PrefixAppend(g, c, V))
4.3 Merging envelopes
Lemma 4.1. Let and be represented on the same interval . Suppose holds exactly on a prefix of this interval. Their pointwise maximum can be represented in time using new function and witness nodes. At equality, the witness of is chosen. Both input trees remain unchanged.
Proof. Consider Algorithm 2. At a leaf, the strict comparison selects the larger score, preferring at equality. Otherwise, Children incorporates the parent suffixes into the child roots. If , the prefix property implies that exceeds throughout the left half. Otherwise, does not exceed anywhere in the right half. Thus one half is selected directly, and only the other requires recursion. Restriction preserves the prefix property, proving correctness by induction.
Each call makes at most one recursive call and otherwise takes time and creates new function and witness nodes. The tree height gives the claimed bounds.
Cached scores allow Merge to construct the pointwise maximum in a single descent. By Lemma 3.2, is applicable whenever the endpoint sets are separated in this value order.
4.4 Evaluation and reporting
Lemma 4.2. A represented score at a given coordinate can be returned in time, and its witness of length k can be reported in time. Neither query changes the stored structure.
Proof. Descend to the coordinate's leaf, collecting the suffixes in root-to-leaf order. By (7), the score is , which is computed in time. The witness is the concatenation . Discard empty handles and expand the remaining forest in this order, visiting the left child of each concatenation before the right child. Every concatenation has two nonempty children. The unfolded forest with leaf occurrences therefore has at most node occurrences, regardless of sharing. Expansion takes time. The traversal uses workspace including the output and allocates no persistent nodes.
5 Preprocessing and queries
We now prove Theorem 1.1. Maintain an ordinary mutable segment tree, denoted outer, on the value domain . Its entries are roots of the persistent trees from Section 4, which are indexed by the left boundary. For an outer node v with value interval , maintain,
Algorithm 2 Merge(f, g) for functions satisfying the prefix property.
1: if the interval is a singleton then 2: if last(g) > last(f) then 3: return g 4: else 5: return f 6: 7: 8: if last(g_{\mathrm{L}}) > last(f_{\mathrm{L}}) then 9: return Join(g_{\mathrm{L}}, Merge(f_{\mathrm{R}}, g_{\mathrm{R}})) 10: else 11: return Join(Merge(f_{\mathrm{L}}, g_{\mathrm{L}}), f_{\mathrm{R}})
immediately before processing position i,
For positive scores, the stored witness is an optimum subsequence ending in this set. For zero scores, it is empty. Initially every entry points to the all-zero tree for .
The outer tree uses Merge as its combine operation. For scores, this operation is pointwise maximum, with identity . Its implementation requires the ordered endpoint sets of Lemma 3.2. Accordingly, outer.prod(0, ) folds the canonical intervals in increasing value order, placing the accumulated lower-value envelope first in each merge. A point assignment outer.set( , ) recomputes ancestors by merging the left child's root with the right child's root. Both operations use merges, all on value-separated endpoint sets. The operation outer.prod() returns the outer root's stored envelope. The outer subdivision is the usual balanced recursive subdivision, so no padding is needed.
Lemma 5.1. Algorithm 3 constructs for every , with optimum witnesses for positive values and empty witnesses for zero values. Its time and total allocated space are .
Proof. We prove (9) and its witness assertion by induction on . They hold initially. The canonical intervals partition . Their ordered merges yield by Lemmas 3.2 and 4.1. For , a predecessor witness of positive weight ends at an earlier position of smaller value, and appending gives a feasible subsequence of weight . A predecessor witness of weight zero is empty and gives the singleton . For , the update leaves the zero value and empty witness unchanged. Thus (4) proves that the new root represents with the required witnesses.
Since the ranks are distinct, the leaf for was previously empty. At each updated ancestor, the child endpoint sets are separated by value. They partition the set in (9) with replaced by . Their merge preserves the invariant and selects an optimum witness. All other outer nodes are unchanged. The outer root consequently represents . Persistence preserves each saved root and its witnesses.
Each iteration uses merges and one prefix append. By Lemma 4.1 and the prefix-update bound, it takes time and allocates function and witness nodes. Relabeling takes time, and building the initial trees takes time and space. The input, mutable outer tree, and saved roots occupy space. Every allocated node has constant size, so even retaining all temporary nodes uses space. The recursion stack uses additional space.
Algorithm 3 Preprocessing the relabeled sequence.
1: Build the full persistent tree for 2: Initialize all entries of outer to 3: 4: for do 5: 6: 7: 8:
Queries. For a nonempty interval , evaluate at . By (3) and Lemma 5.1, its score is , and its witness is an optimum increasing subsequence in the query interval. Lemma 4.2 gives value-query time and reporting time. An empty interval returns zero and an empty list directly. This proves Theorem 1.1.
AI Assistance Disclosure
ChatGPT (OpenAI) assisted with literature searches, algorithm design, proof development and checking, counterexample searches, implementation, and manuscript preparation. The author is responsible for the statements and proofs in this paper.
References
[DSST89] James R. Driscoll, Neil Sarnak, Daniel D. Sleator, and Robert E. Tarjan. Making data structures persistent. Journal of Computer and System Sciences, 38(1):86–124, 1989. doi:10.1016/0022-0000(89)90034-2.
[GGK25] Paweł Gawrychowski, Egor Gorbachev, and Tomasz Kociumaka. Core-sparse Monge matrix multiplication: Improved algorithm and applications. In 33rd Annual European Symposium on Algorithms (ESA 2025), volume 351 of LIPIcs, pages 74:1–74:17. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2025. Full version: arXiv:2408.04613v2. URL: https://arxiv.org/abs/2408.04613v2, doi:10.4230/LIPIcs.ESA.2025.74.
[KR26] Karthik C. S. and Saladi Rahul. Range longest increasing subsequence and its relatives. In 17th Innovations in Theoretical Computer Science Conference (ITCS 2026), volume 362 of LIPIcs, pages 87:1–87:20. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2026. Full version: arXiv:2404.04795v2. URL: https://arxiv.org/abs/2404.04795v2, doi:10.4230/LIPIcs.ITCS.2026.87.
[Sch98] Jeanette P. Schmidt. All highest scoring paths in weighted grid graphs and their application to finding all approximate repeats in strings. SIAM Journal on Computing, 27(4):972–992, 1998. doi:10.1137/S0097539795288489.
[Tis13] Alexander Tiskin. Semi-local string comparison: algorithmic techniques and applications, 2013. arXiv:0707.3619v21. URL: https://arxiv.org/abs/0707.3619v21.
[Tis15] Alexander Tiskin. Fast distance multiplication of unit-Monge matrices. Algorithmica, 71(4):859–888, 2015. doi:10.1007/s00453-013-9830-z.