Ankit_132

D

Nov 22nd, 2023
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         cin>>n;
  15.  
  16.         vector<int> a(n), ca(n), b(n), cb(n);
  17.         for(auto &e: a)     cin>>e;
  18.         for(auto &e: ca)    cin>>e;
  19.         for(auto &e: b)     cin>>e;
  20.         for(auto &e: cb)    cin>>e;
  21.  
  22.         vector<multiset<int>> v(2*n+5);
  23.        
  24.         map<int, int> mp;
  25.  
  26.         for(int i=0; i<n; i++)
  27.         {
  28.             v[ca[i]].insert(a[i]);
  29.             v[cb[i]].insert(b[i]);
  30.             mp[cb[i]] = 1;
  31.         }
  32.  
  33.         int f = 1;
  34.         int x = -1;
  35.  
  36.         for(int i=0; i<n; i++)
  37.         {
  38.             if(!mp[ca[i]])
  39.             {
  40.                 if(x > a[i])        f = 0;
  41.                 x = a[i];
  42.                 continue;
  43.             }
  44.            
  45.             if(v[ca[i]].size()==0 || x>*v[ca[i]].rbegin())
  46.                 f = 0;
  47.             else
  48.             {
  49.                 x = *v[ca[i]].lower_bound(x);
  50.                 v[ca[i]].erase(v[ca[i]].find(x));
  51.             }
  52.         }
  53.  
  54.         if(f)       cout<<"Yes\n";
  55.         else        cout<<"No\n";
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment