fork download
  1. #include<bits/stdc++.h>
  2.  
  3. #pragma GCC optimize("O2")
  4. #pragma GCC optimize("O3")
  5. #pragma GCC optimize("Ofast")
  6.  
  7. #define int long long
  8.  
  9. #define pii pair<int,int>
  10. #define ii int,int
  11. #define fi first
  12. #define se second
  13. #define pb push_back
  14. #define lb lower_bound
  15. #define ub upper_bound
  16. #define umap unordered_map
  17. #define BIT(mask, i) ((mask >> i)&1)
  18. #define ALL(c) c.begin(), c.end()
  19.  
  20. using namespace std;
  21.  
  22. mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count());
  23. int rand(int l, int r){
  24. return l + rd()*rd()%(r-l+1);
  25. }
  26.  
  27. const int N = 1e6+7;
  28. const int M = 1e3+3;
  29. const int MOD = 1e9+7;
  30. const int inf = 3e18;
  31.  
  32. int n;
  33.  
  34. signed main(){
  35. ios_base::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cin >> n;
  39. multiset<int> st;
  40.  
  41. for(int i = 1; i <= n; i++){
  42. int x;
  43. cin >> x;
  44. auto j = st.upper_bound(x);
  45. if(j != st.end()){ // tim duoc vi tri phu hop de chen
  46. st.erase(j);;
  47. }
  48. st.insert(x);
  49. }
  50. cout << st.size();
  51. }
  52.  
  53.  
  54.  
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
Standard output is empty