Skip to content

Instantly share code, notes, and snippets.

@Jangwa
Last active August 29, 2015 13:55
Show Gist options
  • Save Jangwa/8691666 to your computer and use it in GitHub Desktop.
Save Jangwa/8691666 to your computer and use it in GitHub Desktop.
Longest Increasing Sub sequence "Length" O(nLog(n) )
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int a,num[120000],n,ans[120000],sz;
int main(){
while (scanf("%d",&n) == 1){
for(a=0;a<n;a++) scanf("%d",&num[a]);
sz=0;
for(a=0;a<n;a++) {
int* it = lower_bound(ans,ans+sz,num[a]);
if (it != ans+sz) *it=num[a];
else ans[sz++]=num[a];
}
printf("%d\n",sz);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment