Guest User

Untitled

a guest
Jan 7th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class InParser {
  6. private:
  7. FILE *fin;
  8. char *buff;
  9. int sp;
  10.  
  11. char read_ch() {
  12. ++sp;
  13. if (sp == 4096) {
  14. sp = 0;
  15. fread(buff, 1, 4096, fin);
  16. }
  17. return buff[sp];
  18. }
  19.  
  20. public:
  21. InParser(const char* nume) {
  22. fin = fopen(nume, "r");
  23. buff = new char[4096]();
  24. sp = 4095;
  25. }
  26.  
  27. InParser& operator >> (int &n) {
  28. char c;
  29. while (!isdigit(c = read_ch()) && c != '-');
  30. int sgn = 1;
  31. if (c == '-') {
  32. n = 0;
  33. sgn = -1;
  34. } else {
  35. n = c - '0';
  36. }
  37. while (isdigit(c = read_ch())) {
  38. n = 10 * n + c - '0';
  39. }
  40. n *= sgn;
  41. return *this;
  42. }
  43.  
  44. InParser& operator >> (long long &n) {
  45. char c;
  46. n = 0;
  47. while (!isdigit(c = read_ch()) && c != '-');
  48. long long sgn = 1;
  49. if (c == '-') {
  50. n = 0;
  51. sgn = -1;
  52. } else {
  53. n = c - '0';
  54. }
  55. while (isdigit(c = read_ch())) {
  56. n = 10 * n + c - '0';
  57. }
  58. n *= sgn;
  59. return *this;
  60. }
  61. };
  62.  
  63. int n, x;
  64.  
  65. int main(){
  66. ios_base::sync_with_stdio(false);
  67. cin.tie(0);
  68.  
  69. InParser _cin("gogosi.in");
  70. ofstream cout("gogosi.out");
  71.  
  72. vector < int > v;
  73.  
  74. _cin >> n >> x;
  75.  
  76. v.push_back( x );
  77.  
  78. for (int i = 1; i < n; i++){
  79. _cin >> x;
  80.  
  81. int left = 0; int right = v.size() - 1;
  82.  
  83. while (right > left){
  84.  
  85. int mid = (left + right) / 2;
  86.  
  87. if (v[ mid ] <= x)
  88. right = mid;
  89.  
  90. else
  91. left = mid + 1;
  92. }
  93.  
  94. if (v[ right ] <= x)
  95. v[ right ] = x;
  96.  
  97. else
  98. v.push_back( x );
  99. }
  100. cout << v.size();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment