#include<stdio.h>//**O(nlogn)**// #include<string.h> #define min -32769//**int型最小数为-32768**// int stack[100001];//**模拟栈,其实不是栈,为了更好形象比较,嘿嘿**// int main() { int n,i,t,top,low,high,mid; memset(stack,0,sizeof(stack)); while(~scanf("%d",&n)) { top=0;stack[0]=min; for(i=0;i<=n-1;i++) { scanf("%d",&t); if(t>stack[top])//**如果输入进来的数比栈顶的数大,直接插入到栈的**// { top++; stack[top]=t; } else { low=1;high=top; while(low<=high)//**二分查找,寻找插入位置**// { mid=(low+high)/2; if(t>stack[mid]) { low=mid+1; } else { high=mid-1; } } stack[low]=t;//**找到插入位置,并替换点原值**// } } printf("%d\n",top); } return 0; }