• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 24th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #define _CRT_SECURE_NO_WARNINGS
2. #define _USE_MATH_DEFINES
3. #include "bits/stdc++.h"
4. //#include <intrin.h>
5.
6. #define fore(i,a,b) for(int i = a; i < (b); i++)
7. #define fr(i,a,b) for(int i = a - 1; i >= b; i--)
8. #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
9. #define N 300005
10. #define inf 2000000000
11. #define EPS 1e-6
12. #define MOD (ll)1e15
13. #define __builtin_popcount(x) __popcnt(x)
14.
15. using namespace std;
16.
17. typedef long long ll;
18. typedef pair<int, int> pr;
19. typedef pair<int, pair<int, int>> tup;
20.
21. inline void solve()
22. {
23.     int m, n;
24.     cin >> n >> m;
25.     vector<int> v(n);
26.     set<int> p;
27.
28.     fore(i, 0, n)
29.         cin >> v[i];
30.     fore(i, 0, m)
31.     {
32.         int a;
33.         cin >> a;
34.         p.insert(a);
35.     }
36.
37.     vector<int> t = v;
38.     sort(t.begin(), t.end());
39.     map<int, set<int>> mp;
40.     fore(i, 0, n)
41.         mp[t[i]].insert(i);
42.
43.     fore(i, 0, n)
44.     {
45.         int ind = *mp[v[i]].begin();
46.         mp[v[i]].erase(mp[v[i]].begin());
47.
48.         fore(j, min(i, ind), max(i, ind))
49.         {
50.             if (p.find(j + 1) == p.end())
51.             {
52.                 cout << "NO";
53.                 return;
54.             }
55.         }
56.     }
57.
58.     cout << "YES";
59. }
60.
61. int main()
62. {
63.     fast;
64. #if defined(_DEBUG)
65.     freopen("input.txt", "r", stdin);
66.     freopen("output.txt", "w", stdout);
67. #endif
68.     int q = 1;
69.     cin >> q;
70.     while (q--)
71.     {
72.         solve();
73.         cout << '\n';
74.     }
75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top