25 lines
688 B
TypeScript
25 lines
688 B
TypeScript
export {};
|
|
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
|
const N: number = Number(input[0]);
|
|
const A: number[] = input[1].split(" ").map(Number);
|
|
|
|
let LIS: number[] = new Array(N).fill(0);
|
|
let last_idx: number = -1;
|
|
LIS[++last_idx] = A[0];
|
|
|
|
for(let a of A.slice(1)) {
|
|
if(LIS[last_idx] < a) LIS[++last_idx] = a;
|
|
else {
|
|
let [left, right]: number[] = [0, last_idx];
|
|
let mid: number = Math.floor((left + right) / 2);
|
|
while(left < right) {
|
|
if(LIS[mid] < a) left = mid + 1;
|
|
else right = mid;
|
|
|
|
mid = Math.floor((left + right) / 2);
|
|
}
|
|
LIS[mid] = a;
|
|
}
|
|
}
|
|
|
|
console.log(last_idx+1); |