Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include "bits/stdc++.h"
- //#include <intrin.h>
- #define fore(i,a,b) for(int i = a; i < (b); i++)
- #define fr(i,a,b) for(int i = a - 1; i >= b; i--)
- #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- #define N 300005
- #define inf 2000000000
- #define EPS 1e-6
- #define MOD (ll)1e15
- #define __builtin_popcount(x) __popcnt(x)
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pr;
- typedef pair<int, pair<int, int>> tup;
- inline void solve()
- {
- int m, n;
- cin >> n >> m;
- vector<int> v(n);
- set<int> p;
- fore(i, 0, n)
- cin >> v[i];
- fore(i, 0, m)
- {
- int a;
- cin >> a;
- p.insert(a);
- }
- vector<int> t = v;
- sort(t.begin(), t.end());
- map<int, set<int>> mp;
- fore(i, 0, n)
- mp[t[i]].insert(i);
- fore(i, 0, n)
- {
- int ind = *mp[v[i]].begin();
- mp[v[i]].erase(mp[v[i]].begin());
- fore(j, min(i, ind), max(i, ind))
- {
- if (p.find(j + 1) == p.end())
- {
- cout << "NO";
- return;
- }
- }
- }
- cout << "YES";
- }
- int main()
- {
- fast;
- #if defined(_DEBUG)
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int q = 1;
- cin >> q;
- while (q--)
- {
- solve();
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement