fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. #define mod
  4. #define MAX
  5. #define pb push_back
  6. #define mp make_pair
  7. #define pr pair<int,int>
  8.  
  9. using namespace std;
  10.  
  11. int n;
  12. vector<pr >v(100005);
  13.  
  14. int lessthan(pr a,pr b)
  15. {
  16. if(a.first<b.first && a.second<b.second)
  17. return 1;
  18. return 0;
  19. }
  20.  
  21. int CeilIndex(vector<pr >tailTable,int low,int high,pr key)
  22. {
  23. while(low<high)
  24. {
  25. int mid=low+(high-low)/2;
  26. if(lessthan(tailTable[mid],key))
  27. low=mid+1;
  28. else
  29. high=mid;
  30. }
  31. return low;
  32. }
  33.  
  34. int lis()
  35. {
  36. vector<pr >tailTable(100005);
  37. int len=1;
  38. tailTable[0]=v[0];
  39. for(int i=1;i<n;i++)
  40. {
  41. if(lessthan(v[i],tailTable[0]))
  42. tailTable[0]=v[i];
  43. else if(lessthan(tailTable[len-1],v[i]))
  44. tailTable[len++]=v[i];
  45. else
  46. {
  47. tailTable[CeilIndex(tailTable,0,len-1,v[i])]=v[i];
  48. }
  49. }
  50. return len;
  51. }
  52.  
  53. int main()
  54. {
  55. scanf("%d",&n);
  56. int i,a,b;
  57. for(i=0;i<n;i++)
  58. {
  59. scanf("%d%d",&a,&b);
  60. v[i]=mp(a,b);
  61. }
  62.  
  63. printf("%d\n",lis());
  64. return 0;
  65. }
Success #stdin #stdout 0s 3464KB
stdin
8
1 3
3 2
1 1
4 5
6 3
9 9
8 7
7 6
stdout
3