Use the binary search LIS with comparison. In the tails array, use lower_bound for strictly increasing, upper_bound for non-decreasing. For non-decreasing: when element equals , we can extend (not replace). Use upper_bound to find insertion point. Alternatively, for strictly increasing on an array with duplicates: make elements unique by pairing with indices: . Sort lexicographically. Time: with binary search, with naive DP. Space: for the tails array. The binary search approach handles both variants.
Time complexity: .
Space complexity: .