using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 4");
WillReturn.Add("1 2 3 2 4");
WillReturn.Add("2 3 1 4 2");
WillReturn.Add("1 3 1 3");
WillReturn.Add("1 2 3 5");
WillReturn.Add("1 4 2 5");
WillReturn.Add("1 5 1 5");
//Yes
//No
//No
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("4 4");
WillReturn.Add("4 4 4 4");
WillReturn.Add("4 4 4 4");
WillReturn.Add("1 2 2 3");
WillReturn.Add("3 3 1 1");
WillReturn.Add("1 3 1 4");
WillReturn.Add("1 4 2 3");
//Yes
//Yes
//No
//No
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
const long Hou = 99999999999999997; // 17桁での巨大素数
static void Main()
{
List<string> InputList = GetInputList();
long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long[] BArr = InputList[2].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
var InsRandom = new Random();
var RandDict = new Dictionary<long, long>();
foreach (long EachVal in AArr.Concat(BArr)) {
if (RandDict.ContainsKey(EachVal) == false) {
RandDict[EachVal] = InsRandom.Next();
RandDict[EachVal] <<= 32;
RandDict[EachVal] = InsRandom.Next();
RandDict[EachVal] %= Hou;
}
}
// フェニック木の作成
var Ins_Fenwick_Tree_A = new Fenwick_Tree(AArr.GetUpperBound(0), Hou);
var Ins_Fenwick_Tree_B = new Fenwick_Tree(BArr.GetUpperBound(0), Hou);
for (long I = 0; I <= AArr.GetUpperBound(0); I++) {
Ins_Fenwick_Tree_A.Add(I, RandDict[AArr[I]]);
}
for (long I = 0; I <= BArr.GetUpperBound(0); I++) {
Ins_Fenwick_Tree_B.Add(I, RandDict[BArr[I]]);
}
foreach (string EachStr in InputList.Skip(3)) {
SplitAct(EachStr);
long Range1Sta = wkArr[0] - 1;
long Range1End = wkArr[1] - 1;
long Range2Sta = wkArr[2] - 1;
long Range2End = wkArr[3] - 1;
long RangeSum1 = Ins_Fenwick_Tree_A.GetSum(Range1Sta, Range1End);
long RangeSum2 = Ins_Fenwick_Tree_B.GetSum(Range2Sta, Range2End);
if (RangeSum1 == RangeSum2) {
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
}
}
}
// フェニック木
#region Fenwick_Tree
internal class Fenwick_Tree
{
private long[] mBitArr;
private long mExternalArrUB;
private long mHou;
// ノードのIndexの列挙を返す
internal IEnumerable<long> GetNodeIndEnum()
{
for (long I = 0; I <= mExternalArrUB; I++) {
yield return I;
}
}
// 木のノードのUBを返す
internal long GetUB()
{
return mExternalArrUB;
}
// コンストラクタ
internal Fenwick_Tree(long pExternalArrUB, long pHou)
{
mExternalArrUB = pExternalArrUB;
// フェニック木の外部配列は0オリジンで、
// フェニック木の内部配列は1オリジンなため、2を足す
mBitArr = new long[pExternalArrUB + 2];
mHou = pHou;
}
// [pSta,pEnd] のSumを返す
internal long GetSum(long pSta, long pEnd)
{
long Result = GetSum(pEnd) - GetSum(pSta - 1);
Result %= mHou;
if (Result < 0) Result += mHou;
return Result;
}
// [0,pEnd] のSumを返す
internal long GetSum(long pEnd)
{
pEnd++; // 1オリジンに変更
long Sum = 0;
while (pEnd >= 1) {
Sum += mBitArr[pEnd];
Sum %= mHou;
pEnd -= pEnd & -pEnd;
}
if (Sum < 0) Sum += mHou;
return Sum;
}
// [I] に Xを加算
internal void Add(long pI, long pX)
{
pI++; // 1オリジンに変更
pX %= mHou;
while (pI <= mBitArr.GetUpperBound(0)) {
mBitArr[pI] += pX;
mBitArr[pI] %= mHou;
pI += pI & -pI;
}
}
}
#endregion