File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 1
- // Given a list of numbers of length n, this routine extracts a
1
+ // Given a list of numbers of length n, this routine extracts a
2
2
// longest increasing subsequence.
3
3
//
4
4
// Running time: O(n log n)
@@ -21,7 +21,7 @@ typedef vector<PII> VPII;
21
21
VI LongestIncreasingSubsequence (VI v) {
22
22
VPII best;
23
23
VI dad (v.size (), -1 );
24
-
24
+
25
25
for (int i = 0 ; i < v.size (); i++) {
26
26
#ifdef STRICTLY_INCREASNG
27
27
PII item = make_pair (v[i], 0 );
@@ -35,11 +35,11 @@ VI LongestIncreasingSubsequence(VI v) {
35
35
dad[i] = (best.size () == 0 ? -1 : best.back ().second );
36
36
best.push_back (item);
37
37
} else {
38
- dad[i] = dad[it- >second ] ;
38
+ dad[i] = it == best. begin () ? - 1 : prev (it)- >second ;
39
39
*it = item;
40
40
}
41
41
}
42
-
42
+
43
43
VI ret;
44
44
for (int i = best.back ().second ; i >= 0 ; i = dad[i])
45
45
ret.push_back (v[i]);
You can’t perform that action at this time.
0 commit comments