hello
i have been thinking on this problem for a long time link. i would be thankful if anyone has any ideas.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Name |
|---|



I think I have an idea, although I haven't (and probably won't) implemented it yet.
Notice that we have the max length of an LIS being $$$O(\sqrt{N})$$$. Also, if we compress values, each one can also be bounded by $$$O(\sqrt{N})$$$. So, if we could; for each length; find the first moment in time when it's obtainable, we'd be done.
This is easy to do by making $$$\sqrt{N}$$$ different segment trees, each of length $$$\sqrt{N}$$$, and performing a regular LIS dp. Of course, you will need to turn the online problem into an offline one by preprocessing insertions, but this is farily straightforward to do.
The time complexity should be $$$O(N \log{N})$$$, where $$$N=\sum{a_i}$$$.
lis is not bounded by $$$O(\sqrt(N))$$$. the counter example is 1 2 3 4....n.
That is not possible, since $$$\frac{n(n+1)}{2} = O(n^2) \gt 10^6$$$ (recall the bound on the sum of all potatoes). It is bounded by $$$O(\sqrt{n})$$$.
you are right. can you please elaborate more on the segment tree part?
Yes, so you know how in regular LIS dp, we store the $$$\text{dp}[j]$$$ at $$$\text{st}[a[j]]$$$, right?
We do something somewhat similar here. We make $$$O(\sqrt{n})$$$ different segment trees, say the $$$i$$$-th one is $$$\text{trees}[i]$$$. $$$\text{trees}[i]$$$ will store the minimum time (for each and every possible $$$a[j]$$$ value the LIS ends at) that a sequence of length $$$i$$$ is obtainable.
Notice that we can do this, since $$$O(\sqrt{n} \times \sqrt{n}) = O(n)$$$. What would our transitions be? We'd iterate over elements ($$$a[j]$$$) in increasing order of index and set $$$trees[i][a[j]] = \min(\text{trees}[i][a[j]], \max(\text{time}[j], \text{trees}[i-1].\text{query}(1, a[i])))$$$.
In simple words, we're just looking at all sequences of length $$$i-1$$$ and choosing the one with the minimum time. Of course, since we now include $$$a[j]$$$, we should take the max of this and $$$\text{time}[j]$$$ to get our new time.
Notice that we only iterate $$$i$$$ from $$$1$$$ to $$$a[j]$$$ since a sequence of length longer than $$$a[j]$$$ will never have $$$a[j]$$$ as its $$$ \gt a[j]$$$-th element (the 'worst case' is $$$1,2,3,...$$$).
Please ask if you have more questions! I don't know if I did the best job explaining, and I'd be happy to clear any further doubts.