Advertisement
Saleh127

UVA 12747 / LCS-LIS

Jul 25th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. /***
  2.  created: 2022-07-25-23.18.54
  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,i,j,k,l;
  25.  
  26.         cin>>n;
  27.  
  28.         ll a[n+4],b[n+4];
  29.  
  30.         for(i=1;i<=n;i++)
  31.         {
  32.             cin>>m;
  33.             a[m]=i;
  34.         }
  35.         for(i=1;i<=n;i++)
  36.         {
  37.             cin>>m;
  38.             b[i]=a[m];
  39.         }
  40.         vector<ll>x;
  41.         x.push_back(b[1]);
  42.         for(i=2;i<=n;i++)
  43.         {
  44.             k=upper_bound(x.begin(),x.end(),b[i])-x.begin();
  45.             if(k==x.size())
  46.             {
  47.                 x.push_back(b[i]);
  48.             }
  49.             else x[k]=b[i];
  50.         }
  51.         cout<<"Case "<<cs<<": "<<(n-x.size())*2<<nl;
  52.     }
  53.     get_lost_idiot;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement