You are given an array a1,a2,…,an and an array b1,b2,…,bn.
For one operation you can sort in non-decreasing order any subarray a[l…r] of the array aa.
For example, if a=[4,2,2,1,3,1] and you choose subbarray a[2…5], then the array turns into [4,1,2,2,3,1].
You are asked to determine whether it is possible to obtain the array b by applying this operation any number of times (possibly zero) to the array aa.
Input
The first line contains one integer t (1≤t≤3⋅105) — the number of queries.
The first line of each query contains one integer n (1≤n≤3⋅10^5).
The second line of each query contains n integers a1,a2,…,an (1≤ai≤n).
The third line of each query contains n integers b1,b2,…,bn (1≤bi≤n).
It is guaranteed that ∑n≤3⋅105 over all queries in a test.
Output
For each query print YES (in any letter case) if it is possible to obtain an array b and NO (in any letter case) otherwise.
Example
Input
4
7
1 7 1 4 4 5 6
1 1 4 4 5 7 6
5
1 1 3 3 5
1 1 3 3 5
2
1 1
1 2
3
1 2 3
3 2 1
Output
YES
YES
NO
NO
题意:就是让你只能通过对a数组的任意区间进行非递减排序,看能不能变成b数组。
思路:线段树问题,对数组a进行建树,然后对b数组遍历,从a数组中找到第一个与b数组值相等的下标k(因为数组比较大,不可能用两个for循环去找,所以要用队列来储存下标。然后只需到对应的队列去取值就行,如果为空,则说明a数组的值不全等于数组,直接break。),如果在区间<1,k>中数组a的最小值小于b当前的值,那么你无论如何变换都无法实现。如果大于或等于,那么就说明当前值为区间最小值,则可以通过变换将其换到b数组对应的位置,再将权值设为inf。
代码如下:
#include <bits/stdc++.h>
#define inf 999999
using namespace std;
const int maxn = 3e5+5;
int num[maxn],num2[maxn],Q,n;
queue<int>q[maxn];
int G[maxn*4];
void buildtree(int l,int r,int t)
{
if(l==r){
G[t] = num[l];
return ;
}
int mid = (int)(l