-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Array_and_Permutation.cpp
More file actions
69 lines (65 loc) · 1.36 KB
/
B_Array_and_Permutation.cpp
File metadata and controls
69 lines (65 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define input for(int &i:v) cin >> i;
#define inputb for(int &i:b) cin >> i;
void print(const vector<int>& v) {
for (int i : v) {
cout << i << " ";
}
cout << endl;
}
bool cont(vector<int>&b){
int n = b.size();
vector<bool>seen(n+1,false);
for(int i=0;i<n;i++)
{
if(seen[b[i]]) return false;
while(i+1<n && b[i+1]==b[i]){
i++;
}
seen[b[i]] = true;
}
return true;
}
bool order(vector<int>&a, vector<int>&b){
int n = a.size();
vector<int> blocks;
for(int i = 0; i < n; i++){
if(i == 0 || b[i] != b[i-1]){
blocks.push_back(b[i]);
}
}
int j = 0;
for(int x : blocks){
while(j < n && a[j] != x){
j++;
}
if(j == n) return false;
j++;
}
return true;
}
void solve() {
int n; cin >> n;
vector <int> v(n),b(n);
input
inputb
// cout << cont(b) << endl;
// cout << order(v,b) << endl;
if(cont(b) && order(v,b)){
yes return;
}
no
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t-- > 0) {
solve();
}
}