i wish that anyone explains to me in simple way the algorithm of the Longest Increasing Subsequence in O(nlogn) time , cuz i actually read all online articles about it and found no one explain it well , thanks in advance :)
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
i wish that anyone explains to me in simple way the algorithm of the Longest Increasing Subsequence in O(nlogn) time , cuz i actually read all online articles about it and found no one explain it well , thanks in advance :)
Название |
---|
i learned LIS from here. it's pretty good :)
Is this possible to do binarysearch in an unsorted array?
the trick for the nlogn solution is to maintain, in addition to your dp table, an auxiliary table A so that A[ i ] holds the information "what is the minimum number in the array, such that an increasing subsequence of length i terminates at", it is easy to see that this array will be strictly increasing. Therefore, we can simply binary search the solution of every subproblem and update our array.
It is also worth mentioning that you can do LIS in O(n log n) time simply by improving the O(n^2) DP. Everything you need is coordinate compression and a Fenwick tree / interval tree. The code is longer than with the bsearching algorithm, but for many people the idea is simpler because it uses tools they already know.
I think it can be done without coordinate compression by processing in increasing order of value and using a segment tree in O(n log n).
Edit: sorry for necroposting, didn't realise this blog was from 5 years ago.
Yes there is
But how to retain the LIS? This is fine for calculating its length. But what about the LIS itself?
It's not possible with the set method, just use segment tree.
Could you tell me how to retain LIS(sequence itself not the length) using segment trees?
Do the DP and find longest sequence with end value less than current value at index below us, augment the segment tree to return both max and index, then just step back the indices.
It is possible with set. At each $$$i$$$, you should store the previous element's index in the LIS that contains $$$a_i$$$. For details see this comment.
Here it is
It does not work if there are duplicates in a. e.g a = [1, 2, 3, 4, 1] It will give 3 but correct ans is 4
Yes it is, sorry for not writting the notice
Found this Implementation with vector
Well yeah,there are a lot of articles and finally I found a video which explains the NlogN algorithm with an example step by step and the actual idea/logic behind it.You can refer it : https://youtu.be/nf3YG4CnTbg