#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], b[maxn], cnt[maxn];
int main() {
int t, n;
cin >> t;
while(t--) {
cin >> n;
for(int i=1; i<=n; ++i) cin >> a[i];
for(int i=1; i<=n; ++i) cin >> b[i];
for(int i=1; i<=n; ++i) cnt[i] = 0;
bool fl = true;
for(int i=n, j=n; i>=1; --i) {
while(j>1 && b[j] == b[j-1]) ++cnt[b[j]], --j;//保证b[j]有一个可以与之对应
if(j>=1 && a[i] == b[j]) --j;//相等往前走
else if(cnt[a[i]] > 0) --cnt[a[i]];//否则如果有个b[j]与a[i]对应,那么就让这个b[j]的值退到后面且减掉
else {//否则就结束
fl = false;
cout << "NO" << endl;
break;
}
}
if(fl) cout << "YES" << endl;
}
return 0;
}
D. Cyclic Rotation
最新推荐文章于 2024-09-16 17:46:36 发布