fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int> LIS(const vector<int> &A) {
  4. vector<int> odpoved;
  5. vector<int> konce(1,-(1<<30));
  6. for (int a : A) {
  7. auto kam = lower_bound( konce.begin(), konce.end(), a );
  8. odpoved.push_back( kam - konce.begin() );
  9. if (kam == konce.end()) konce.push_back(a); else *kam = a;
  10. }
  11. return odpoved;
  12. }
  13.  
  14. int main() {
  15. int N;
  16. cin >> N;
  17. vector<int> F(N);
  18. for (int n=0; n<N; ++n) cin >> F[n];
  19. vector<int> vysl = LIS(F);
  20. for (int n=0; n<vysl.size(); ++n) cout << vysl[n] << " ";
  21. return 0;
  22. }
Success #stdin #stdout 0s 15240KB
stdin
3
1 1 1
9
2 6 3 4 1 2 9 5 8
5
5 4 3 2 3
stdout
1 1 1