Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- //#define int ll
- //#define double ld
- #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define pii pair<int , int>
- #define pb emplace_back
- //#define endl '\n'
- #define all(x) (x).begin() , (x).end()
- #define rall(x) (x).rbegin() , (x).rend()
- #define F first
- #define S second
- const int mod = 1e9 + 7;
- const int MAXX = 2e5 + 15;
- const int N = 1e6;
- const int INF = 1e18 + 123;
- int t , n , m , g , pos , ind , h , l;
- int a[MAXX];
- int b[MAXX];
- int x[MAXX];
- map<int , int> cnt;
- int main()
- {
- _FastIO;
- scanf("%d" , &t);
- while(t--){
- scanf("%d" , &n);
- for(int i = 1; i <= n; i++){
- scanf("%d" , &a[i]);
- }
- for(int i = 1; i <= n; i++){
- scanf("%d" , &b[i]);
- }
- scanf("%d" , &m);
- vector<int> v;
- vector<int>::iterator op;
- for(int i = 0; i < m; i++){
- scanf("%d" , &x[i]);
- if(!cnt[x[i]])
- v.pb(x[i]);
- cnt[x[i]]++;
- }
- sort(rall(v));
- bool ok = true;
- for(int i = 1; i <= n; i++){
- if(a[i] < b[i]){
- ok = false;
- break;
- }
- if(a[i] == b[i])
- continue;
- if(!cnt[b[i]]){
- ok = false;
- break;
- }
- }
- if(!ok){
- for(int i = 0; i < m; i++){
- cnt[x[i]] = 0;
- }
- printf("NO");
- putchar('\n');
- continue;
- }
- multiset<pair<int , int> > ms;
- multiset<pair<int , int> >::iterator it;
- multiset<int> used;
- multiset<int>::iterator orr;
- used.insert(0);
- for(int i = 1; i <= n; i++){
- if(b[i] > v[0]){
- used.insert(i);
- }
- }
- used.insert(n + 1);
- for(int i = 1; i <= n; i++){
- if(b[i] < a[i])
- ms.insert({b[i] , i});
- if(b[i] == a[i])
- ms.insert({b[i] , -1});
- }
- for(int k : v){
- set<int> myset;
- vector<int> ox;
- while(!ms.empty()){
- it = ms.end();
- it--;
- g = it->F;
- ind = it->S;
- if(ind == -1){
- ms.erase(it);
- ox.pb(ind);
- continue;
- }
- if(g == k){
- ms.erase(it);
- orr = used.lower_bound(ind);
- orr--;
- ox.pb(ind);
- h = *orr;
- myset.insert(h);
- }else{
- break;
- }
- }
- l = (int)myset.size();
- //cout << k << " " << l << endl;
- if(cnt[k] < l){
- ok = false;
- break;
- }
- for(int i : ox){
- used.insert(i);
- }
- }
- for(int i = 0; i < m; i++){
- cnt[x[i]] = 0;
- }
- if(ok){
- printf("YES");
- putchar('\n');
- continue;
- }
- printf("NO");
- putchar('\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement