fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void solve() {
  6. int n;
  7. cin >> n;
  8.  
  9. vector<int> a(n), p(n), pos(n+1);
  10. for (int i=0; i<n; i++) {
  11. cin >> p[i];
  12. pos[p[i]] = i;
  13. }
  14. for (int i=0; i<n; i++)
  15. cin >> a[i];
  16.  
  17. int lst = -1;
  18. for (int i=0; i<n; i++) {
  19. if (pos[a[i]] < lst) {
  20. cout << "NO";
  21. return;
  22. }
  23.  
  24. lst = pos[a[i]];
  25. }
  26.  
  27. cout << "YES";
  28. }
  29.  
  30. int main() {
  31. ios_base::sync_with_stdio(0);
  32. cin.tie(0);
  33. cout.tie(0);
  34.  
  35. int t = 1;
  36. cin >> t;
  37. while (t--) {
  38. solve();
  39. cout << "\n";
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5320KB
stdin
6
3
1 2 3
1 2 2
4
3 1 2 4
3 4 2 2
5
1 3 2 5 4
3 3 3 5 4
7
3 7 4 2 1 6 5
3 3 4 4 5 6 5
7
1 2 3 4 5 6 7
7 7 7 7 7 7 7
7
1 3 2 7 5 4 6
2 2 7 7 7 5 6
stdout
YES
NO
YES
NO
YES
YES