OMEGAHEAD_MonkoX

Untitled

Apr 17th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5.  
  6.  
  7.  
  8. using namespace std;
  9.  
  10. template<class ForwardIt, class T>
  11. ForwardIt upper_bound(ForwardIt first, ForwardIt last, const T& value)
  12. {
  13. ForwardIt it;
  14. typename iterator_traits<ForwardIt>::difference_type count, step;
  15. count = distance(first, last);
  16.  
  17. while (count > 0) {
  18. it = first;
  19. step = count / 2;
  20. std::advance(it, step);
  21. if (!(value < *it)) {
  22. first = ++it;
  23. count -= step + 1;
  24. }
  25. else
  26. count = step;
  27. }
  28. return first;
  29. }
  30.  
  31.  
  32. const int MOD = 1e6 + 7;
  33.  
  34.  
  35. void VIVOD(vector<vector<int> > vec2, int n, int m)
  36. {
  37. for (auto i = 0; i < n; ++i)
  38. {
  39. for (auto j = 0; j < m; ++j)
  40. {
  41. cout << vec2[i][j] << " ";
  42. }
  43. cout << endl;
  44. }
  45. }
  46.  
  47. int m(char c1, char c2)
  48. {
  49. if (c1 == c2)
  50. return 0;
  51. return 1;
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.  
  58. int n, o = 1, w = 0, q = 0;
  59. cin >> n;
  60. vector<int> vec(n + 1, 0), vec2(n + 1, 0), ans, a(n + 1), vec3(n + 1, 0);
  61. vec2[0] = -1;
  62. vec[0] = -100001;
  63. for (auto i = 0; i < n; ++i)
  64. {
  65. cin >> a[i];
  66. }
  67. for (auto i = 1; i <= n; i++)
  68. {
  69. vec[i] = MOD;
  70. }
  71. for (auto i = 0; i < n; i++)
  72. {
  73. auto j = upper_bound(vec.begin(), vec.end(), a[i]);
  74. q = j - vec.begin();
  75. if (vec[q - 1] < a[i] && a[i] < vec[q])
  76. {
  77. vec[q] = a[i];
  78. vec2[q] = i;
  79. vec3[i] = vec2[q - 1];
  80. w = max(w, q);
  81. o = vec2[w];
  82. }
  83. }
  84. while (o != -1)
  85. {
  86. ans.push_back(a[o]);
  87. o = vec3[o];
  88. }
  89. cout << ans.size();
  90. }
  91. /*
  92. EXPONENTIAL
  93. POLYNOMIAL
  94. 41 83 67 35 71 43
  95. */
Add Comment
Please, Sign In to add comment