A strictly increasing subsequence of length must be . Let be the position of . Whenever , a later copy is necessary. Greedily moving to the next copy exactly in these cases is sufficient. Thus the answer is one plus the number of such descents. Time and space are ; the answer is at most . The naive solution for the small subtask appends copies and maintains LIS tails. At most copies are needed, giving time and space.
Solution written by GPT6