Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n), ca(n), b(n), cb(n);
- for(auto &e: a) cin>>e;
- for(auto &e: ca) cin>>e;
- for(auto &e: b) cin>>e;
- for(auto &e: cb) cin>>e;
- vector<multiset<int>> v(2*n+5);
- map<int, int> mp;
- for(int i=0; i<n; i++)
- {
- v[ca[i]].insert(a[i]);
- v[cb[i]].insert(b[i]);
- mp[cb[i]] = 1;
- }
- int f = 1;
- int x = -1;
- for(int i=0; i<n; i++)
- {
- if(!mp[ca[i]])
- {
- if(x > a[i]) f = 0;
- x = a[i];
- continue;
- }
- if(v[ca[i]].size()==0 || x>*v[ca[i]].rbegin())
- f = 0;
- else
- {
- x = *v[ca[i]].lower_bound(x);
- v[ca[i]].erase(v[ca[i]].find(x));
- }
- }
- if(f) cout<<"Yes\n";
- else cout<<"No\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment