fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Sonic ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. #define tests(t) int t; cin >> t; while(t--)
  5. #define F first
  6. #define S second
  7. #define pb push_back
  8. #define eb emplace_back
  9. #define ln cout<<endl;
  10. #define sz(x) int((x).size())
  11. #define all(x) (x).begin(), (x).end()
  12. #define rall(x) (x).rbegin(), (x).rend()
  13. #define read(x) for(auto &el : x) cin >> el;
  14. #define reads(s, n) for(int i = 0, x; i < n; ++i) {cin >> x; s.insert(x);}
  15. #define forn(i,n) for(int i=0; i < int(n); ++i)
  16. #define forsn(i, s, n) for (int i = s; i < n; ++i)
  17. #define dforn(i, n) for (int i = n - 1; i >= 0; --i)
  18. #define DBG(x) cout << #x << " = " << x << endl;
  19. #define print(x) for(auto &el : x) {cout << el << " ";} cout<<endl;
  20. #define lw(c, x) int(lower_bound((c).begin(), (c).end(), (x)) - (c).begin())
  21. #define up(c, x) int(upper_bound((c).begin(), (c).end(), (x)) - (c).begin())
  22. #define sino(b) cout<<(b ? "YES\n":"NO\n");
  23. #define syso(x) cout<< (x) <<endl;
  24. typedef long long ll;
  25. typedef long double ld;
  26. typedef vector<int> vi;
  27. typedef vector<ll> vll;
  28. typedef pair<int,int> pii;
  29. typedef pair<int,pii> piii;
  30. typedef pair<ll,ll> pll;
  31. ll gcd(ll a, ll b){while(b){a%=b; swap(a,b);} return a;} ll lcm(ll a,ll b){return a*b/gcd(a,b);}
  32. int lg2(const int &x) { return 31-__builtin_clz(x);} // int lg2(const ll &x) {return 63-__builtin_clzll(x);}
  33. // Para leer e imprimir .txt
  34. // freopen("input.txt", "r", stdin);
  35. // freopen("output.txt", "w", stdout);
  36.  
  37. void solve(){
  38. int n; cin >> n;
  39. set<int> s;
  40. map<int,int> mp;
  41. int ans = 0;
  42. forn(i,n) {
  43. int x; cin >> x;
  44. if (s.upper_bound(x)==s.end()) ans++;
  45. else {
  46. mp[*s.upper_bound(x)]--;
  47. if (!mp[*s.upper_bound(x)]) s.erase(*s.upper_bound(x));
  48. }
  49. s.insert(x);
  50. mp[x]++;
  51. }
  52. syso(ans)
  53. }
  54.  
  55. int main(){
  56. Sonic
  57. // tests(t)
  58. solve();
  59. return 0;
  60. }
  61. //"Quiero picha" - Sebastian Nieto 2026
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0