Korotkodul

НАИБОЛЬШАЯ НЕВОЗРАСТ-Я П-ТЬ за n*log(n)

Jan 6th, 2022 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. void cv(vector <ll> &v){
  15.     for (auto x: v) cout<<x<<' ';
  16.     cout<<"\n";
  17. }
  18.  
  19. void cvv(vector <vector <ll> > &v){
  20.     for (auto x: v) cv(x);
  21.     cout<<"\n";
  22. }
  23. ll inf = pow(2, 31);
  24. int main()
  25. {
  26.     /*ios::sync_with_stdio(0);
  27.     cin.tie(0);
  28.     cout.tie(0);*/
  29.     int n; cin>>n; vector<ll>a(n); for (ll &x: a) cin>>x;
  30.     vector <ll> dp(n), optA(n+1, inf); optA[0] = -inf;
  31.     for (int i=0;i<n;++i){ //cout<<"i = "<<i<<"\n";
  32.         ll l = 0, r = n+1, m;
  33.         cout<<"i = "<<i<<"\n";
  34.         cout<<"dp\n";
  35.         cv(dp);
  36.         cout<<"optA\n";
  37.         cv(optA);
  38.         while (l + 1 < r){
  39.             m = (l+r) / 2;
  40.             //cout<<"m = "<<m<<"\n";
  41.             if (optA[m] >= a[i]){
  42.                 l = m;
  43.             }
  44.             else r = m;
  45.         }
  46.         dp[i]  = l;
  47.         optA[dp[i]] = a[i];
  48.     }
  49.     cv(dp);
  50.     cv(optA);
  51.     //cout<<*max_element(dp.begin(), dp.end())<<"\n";
  52. }
  53. /*
  54. 5
  55. 5 8
  56. 10   4  1
  57.  
  58. 10
  59. 10 9 8 7 6 5 4 100 2 1
  60.  
  61.  
  62. 7
  63. 7 6 5 4 10 2 1
  64. */
  65.  
Add Comment
Please, Sign In to add comment