Advertisement
Saleh127

Light OJ 1277 / Modified LCS/LDS

Jul 24th, 2022
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. /***
  2.  created: 2022-07-25-02.31.10
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16. int main()
  17. {
  18.     ios_base::sync_with_stdio(0);
  19.     cin.tie(0);
  20.     cout.tie(0);
  21.  
  22.     test
  23.     {
  24.         ll n,m,q,i,l,k;
  25.  
  26.         cin>>n>>q;
  27.  
  28.         vector<ll>x(n);
  29.  
  30.         vector<ll>a(n);
  31.  
  32.         vector<ll>lds(n,0);
  33.  
  34.         for(i=0; i<n; i++)
  35.         {
  36.             cin>>x[i];
  37.         }
  38.  
  39.         for(i=0; i<n; i++) a[i]=1e9;
  40.  
  41.         for(i=n-1; i>=0; i--)
  42.         {
  43.             k=lower_bound(a.begin(),a.end(),-x[i])-a.begin();
  44.             lds[i]=k+1;
  45.             a[k]=-x[i];
  46.         }
  47.  
  48.         cout<<"Case "<<cs<<":"<<nl;
  49.  
  50.         l=*max_element(lds.begin(),lds.end());
  51.  
  52.         while(q--)
  53.         {
  54.             cin>>m;
  55.  
  56.             if(m>l) cout<<"Impossible"<<nl;
  57.             else
  58.             {
  59.                 ll last=-1e17;
  60.  
  61.                 for(i=0;i<n && m;i++)
  62.                 {
  63.                     if(lds[i]>=m && last<x[i])
  64.                     {
  65.                         cout<<x[i]<<" ";
  66.                         last=x[i];
  67.                         m--;
  68.                     }
  69.                 }
  70.  
  71.                 cout<<nl;
  72.             }
  73.         }
  74.     }
  75.  
  76.     get_lost_idiot;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement