Nobody knows, but $N$ frogs live in Chef's garden.
Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$.
Chef knows all $P$ pairs of frogs, which want to send messages. Help him to define can they or not!
Note : More than $1$ frog can be on the same point on the X-axis.

-----Input-----
- The first line contains three integers $N$, $K$ and $P$.
- The second line contains $N$ space-separated integers $A_1$, $A_2$, …, $A_N$ denoting the x-coordinates of frogs".
- Each of the next $P$ lines contains two integers $A$ and $B$ denoting the numbers of frogs according to the input.

-----Output-----
For each pair print "Yes" without a brackets if frogs can speak and "No" if they cannot.

-----Constraints-----
- $1 \le N, P \le 10^5$
- $0 \le A_i, K \le 10^9$
- $1 \le A, B \le N$

-----Example-----

-----Sample Input:-----
5 3 3
0 3 8 5 12
1 2
1 3
2 5

-----Sample Output:-----
Yes
Yes
No

-----Explanation-----
- 
For pair $(1, 2)$ frog $1$ can directly speak to the frog $2$ as the distance between them is $3 - 0 = 3 \le K$ . 
- 
For pair $(1, 3)$ frog $1$ can send a message to frog $2$, frog $2$ can send it to frog $4$ and it can send it to frog $3$.
- 
For pair $(2, 5)$ frogs can't send a message under current constraints.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Sorting

Data structures


Solutions:
st = input().split()
N = int(st[0])
K = int(st[1])
P = int(st[2])
st = input().split()
L = []
for x in range(N):
	n = int(st[x])
	L.append([n, x + 1])
L.sort()
H = [0 for x in range(N + 1)]
x = L[0][0]
f = L[0][1]
hf = f
H[f] = hf
for k in range(1, N):
	nx = L[k][0]
	f = L[k][1]
	if nx - x > K:
		hf = f
	H[f] = hf
	x = nx
for k in range(P):
	st = input().split()
	A = int(st[0])
	B = int(st[1])
	if H[A] == H[B]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
s = list(map(int, input().split()))
li = []
for i in range(len(s)):
	li.append([s[i], i])
li.sort()
sort_index = []
for x in li:
	sort_index.append(x[1])
s.sort()
sort_index1 = []
dp = [0] * n
for i in range(1, n):
	if s[i] - s[i - 1] <= k:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = 0
dict1 = {}
for i in range(0, n):
	dict1[sort_index[i]] = i
for i in range(0, p):
	(a, b) = map(int, input().split())
	if a == b:
		print('Yes')
		continue
	newa = dict1[a - 1]
	newb = dict1[b - 1]
	if newb > newa:
		temp = newa
		newa = newb
		newb = temp
	if dp[newa] >= newa - newb:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
c = list(map(int, input().split()))
pairs = list(enumerate(c))
pairs.sort(key=lambda x: x[1])
d = {pairs[i][0]: i for i in range(n)}
dp = [0] * (n + 1)
dp[1] = 1
for i in range(1, n):
	if pairs[i][1] - pairs[i - 1][1] <= k:
		dp[i + 1] = 1
for i in range(1, n + 1):
	dp[i] += dp[i - 1]
for i in range(p):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	(idx1, idx2) = (d[a], d[b])
	mx = max(idx1, idx2) + 1
	mn = min(idx1, idx2) + 1
	print('Yes' if dp[mx] - dp[mn] == mx - mn else 'No')


(n, k, p) = map(int, input().split())
x = [int(x) for x in input().split()]
l = sorted(set(x))
m = 0
l1 = {l[0]: 0}
for i in range(1, len(l)):
	if l[i] - l[i - 1] > k:
		m += 1
	l1[l[i]] = m
for _ in range(p):
	(a, b) = map(int, input().split())
	(a, b) = (x[a - 1], x[b - 1])
	print('Yes') if l1[a] == l1[b] else print('No')


def solve():
	(n, k, p) = map(int, input().split())
	arr = sorted(list(zip(map(int, input().split()), range(n))))
	grp = [0 for i in range(n)]
	grp[arr[0][1]] = 1
	for i in range(1, n):
		if arr[i][0] - arr[i - 1][0] <= k:
			grp[arr[i][1]] = grp[arr[i - 1][1]]
		else:
			grp[arr[i][1]] = grp[arr[i - 1][1]] + 1
	for i in range(p):
		(src, dest) = map(int, input().split())
		(src, dest) = (src - 1, dest - 1)
		if grp[src] == grp[dest]:
			print('Yes')
		else:
			print('No')
solve()


(n, k, p) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append((a[i], i))
b.sort(key=lambda y: y[0])
mp = {}
cur = 1
mp[b[0][1]] = cur
for i in range(1, n):
	if b[i][0] - b[i - 1][0] <= k:
		mp[b[i][1]] = cur
	else:
		cur += 1
		mp[b[i][1]] = cur
for i in range(p):
	(u, v) = map(int, input().split())
	if mp[u - 1] == mp[v - 1]:
		print('Yes')
	else:
		print('No')


(N, K, P) = map(int, input().split())
A = list(map(int, input().split()))
S = sorted(A)
fmap = {S[0]: 0}
m = 0
for i in range(N - 1):
	if S[i + 1] - S[i] > K:
		m += 1
	fmap[S[i + 1]] = m
for i in range(P):
	(a, b) = map(int, input().split())
	(a, b) = (A[a - 1], A[b - 1])
	if fmap[a] == fmap[b]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
d1 = {}
dp = []
for i in range(len(l)):
	d[i + 1] = l[i]
l.sort()
for i in range(len(l)):
	d1[l[i]] = i
	dp.append(l[i])
for i in range(1, len(l)):
	if l[i] - l[i - 1] <= k:
		dp[i] = dp[i - 1]
for _ in range(p):
	(x, y) = map(int, input().split())
	a = dp[d1[max(d[x], d[y])]]
	if a <= min(d[x], d[y]):
		print('Yes')
	else:
		print('No')


(N, K, P) = [int(x) for x in input().split()]
fList = [int(x) for x in input().split()]
sList = sorted(fList)
fMap = {sList[0]: 0}
m = 0
for i in range(N - 1):
	if sList[i + 1] - sList[i] > K:
		m += 1
	fMap[sList[i + 1]] = m
for ii in range(P):
	(A, B) = [int(x) for x in sorted(input().split())]
	(A, B) = (fList[A - 1], fList[B - 1])
	if fMap[A] == fMap[B]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
f = list(map(int, input().split()))
seq = sorted(set(f))
m = 0
seq1 = {seq[0]: 0}
for i in range(1, len(seq)):
	if seq[i] - seq[i - 1] > k:
		m += 1
	seq1[seq[i]] = m
while p > 0:
	(i, j) = map(int, input().split())
	(i, j) = (f[i - 1], f[j - 1])
	if seq1[i] == seq1[j]:
		print('Yes')
	else:
		print('No')
	p -= 1


from sys import stdin
input = stdin.readline

def solve():
	(n, k, p) = map(int, input().split())
	frogs = list(map(int, input().split()))
	tmp = [[frogs[i], i] for i in range(n)]
	tmp.sort()
	which = [0] * (n + 1)
	for i in range(n):
		which[tmp[i][1] + 1] = i
	cnt = [0] * (n + 1)
	for i in range(2, n + 1):
		cnt[i] = cnt[i - 1] + (tmp[i - 1][0] - tmp[i - 2][0] > k)
	ans = []
	for i in range(p):
		(a, b) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		if cnt[which[b] + 1] - cnt[which[a] + 1]:
			ans.append('No')
		else:
			ans.append('Yes')
	print('\n'.join(ans))
solve()


import sys
(n, k, p) = [int(x) for x in sys.stdin.readline().rstrip('\n').split()]
frog = [int(x) for x in sys.stdin.readline().rstrip('\n').split()]
frog_ind = []
for i in range(0, n):
	frog_ind.append([frog[i], i])
frog_ind.sort(key=lambda x: x[0])
group = [0] * n
stack = []
group_id = 0
for elem in frog_ind:
	if stack == []:
		stack.append(elem[0])
	elif abs(stack[-1] - elem[0]) <= k:
		stack.append(elem[0])
	else:
		stack.clear()
		stack.append(elem[0])
		group_id += 1
	group[elem[1]] = group_id
for _ in range(p):
	(a, b) = [int(x) for x in sys.stdin.readline().rstrip('\n').split()]
	if group[a - 1] == group[b - 1]:
		print('Yes')
	else:
		print('No')


(n, k, p) = list(map(int, input().strip().split()))
list1 = list(map(int, input().strip().split()))
list2 = sorted(list1)
map1 = dict()
curr = list2[0]
index = 0
for i in range(1, n):
	if list2[i] - list2[i - 1] > k:
		for j in range(index, i):
			map1[list2[j]] = list2[i - 1]
		curr = list2[i]
		index = i
for j in range(index, n):
	map1[list2[j]] = list2[n - 1]
for _ in range(p):
	(a, b) = list(map(int, input().strip().split()))
	pos1 = list1[a - 1]
	pos2 = list1[b - 1]
	start = min(pos1, pos2)
	end = max(pos1, pos2)
	if map1[start] >= end:
		print('Yes')
	else:
		print('No')


import heapq as hq
[N, K, Q] = [int(p) for p in input().split()]
a = [int(p) for p in input().split()]
b = []
c = [1] * N
c1 = 1
for i in range(N):
	hq.heappush(b, (a[i], i))
(x1, y1) = hq.heappop(b)
for i in range(N - 1):
	(x, y) = hq.heappop(b)
	if x - x1 > K:
		c1 = c1 + 1
	c[y] = c1
	x1 = x
for i in range(Q):
	[r, s] = [int(p) for p in input().split()]
	if c[r - 1] == c[s - 1]:
		print('Yes')
	else:
		print('No')


from collections import defaultdict

def precompute(arr, n, k):
	nonlocal maxdistance
	arr = list(enumerate(arr))
	arr.sort(key=lambda x: -x[1])
	maxdistance[arr[0][0]] = arr[0][1] + k
	for i in range(1, n):
		if arr[i - 1][1] - arr[i][1] <= k:
			maxdistance[arr[i][0]] = maxdistance[arr[i - 1][0]]
		else:
			maxdistance[arr[i][0]] = arr[i][1] + k

def answer(x, y):
	nonlocal maxdistance
	if maxdistance[x - 1] == maxdistance[y - 1]:
		return 'Yes'
	return 'No'
maxdistance = defaultdict(int)
(n, k, q) = list(map(int, input().split()))
arr = list(map(int, input().split()))
precompute(arr, n, k)
for _ in range(q):
	(x, y) = list(map(int, input().split()))
	print(answer(x, y))


(n, k, p) = [int(i) for i in input().split()]
n_sep = list(map(int, input().split()))
count = 0
sep_sort = sorted(n_sep)
hashing = {sep_sort[0]: 0}
for j in range(1, n):
	if abs(sep_sort[j] - sep_sort[j - 1]) > k:
		count += 1
	hashing[sep_sort[j]] = count
for i in range(p):
	pair = list(map(int, input().split()))
	if hashing[n_sep[pair[1] - 1]] == hashing[n_sep[pair[0] - 1]]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
A = list(map(int, input().split()))
frog = sorted(A)
dis = {}
for i in A:
	dis[i] = i
dis[frog[-1]] += k
for i in range(n - 2, -1, -1):
	if frog[i + 1] - frog[i] <= k:
		dis[frog[i]] = dis[frog[i + 1]]
	else:
		dis[frog[i]] += k
for _ in range(p):
	(i, j) = map(int, input().split())
	if dis[A[i - 1]] == dis[A[j - 1]]:
		print('Yes')
	else:
		print('No')


(n, k, p) = list(map(int, input().split()))
a = list(map(int, input().split()))
newar = []
for i in range(n):
	newar.append((a[i], i))
newar.sort(key=lambda x: x[0])
revmap = [0] * n
ans = [0] * n
ctr = 1
ans[0] = ctr
for i in range(n):
	revmap[newar[i][1]] = i
	if i != n - 1:
		if newar[i + 1][0] - newar[i][0] <= k:
			ans[i + 1] = ctr
		else:
			ctr += 1
			ans[i + 1] = ctr
for _ in range(p):
	(A, B) = list(map(int, input().split()))
	if ans[revmap[A - 1]] == ans[revmap[B - 1]]:
		print('Yes')
	else:
		print('No')


from sys import stdin
(n, k, p) = map(int, stdin.readline().split())
list1 = list(map(int, stdin.readline().split()))
list2 = []
for i in range(n):
	list2.append((list1[i], i + 1))
list2.sort(reverse=True)
dict1 = {}
dict1[list2[0][1]] = list2[0][0] + k
prev = list2[0]
for each in list2[1:]:
	if each[0] + k < prev[0]:
		dict1[each[1]] = each[0] + k
		prev = each
	else:
		dict1[each[1]] = dict1[prev[1]]
		prev = each
for j in range(p):
	(a, b) = map(int, stdin.readline().split())
	if dict1[a] == dict1[b]:
		print('Yes')
	else:
		print('No')


(n, k, q) = map(int, input().split())
b = list(map(int, input().split()))
a = sorted(b)
ans = {}
ans[a[0]] = a[0]
start = a[0]
for i in range(n - 1):
	if a[i + 1] - a[i] <= k:
		ans[a[i + 1]] = start
	else:
		start = a[i + 1]
		ans[a[i + 1]] = start
for u in range(q):
	(x, y) = map(int, input().split())
	if ans[max(b[y - 1], b[x - 1])] <= min(b[x - 1], b[y - 1]):
		print('Yes')
	else:
		print('No')


from collections import defaultdict
(N, K, P) = map(int, input().split())
A = list(map(int, input().split()))
l = sorted(A)
d = defaultdict(int)
x = 0
d[l[0]] = x
for i in range(1, N):
	if l[i] - l[i - 1] <= K:
		d[l[i]] = x
	else:
		x += 1
		d[l[i]] = x
for i in range(P):
	(x, y) = map(int, input().split())
	if d[A[x - 1]] == d[A[y - 1]]:
		print('Yes')
	else:
		print('No')


class union_find:

	def __init__(self, N):
		self.parent = {}
		self.rank = []
		for i in range(N):
			self.parent[i] = i
			self.rank.append(0)

	def find(self, x):
		y = x
		while x != self.parent[x]:
			x = self.parent[x]
		self.parent[y] = x
		return x

	def union(self, x, y):
		px = self.find(x)
		py = self.find(y)
		if px == py:
			return
		elif self.rank[px] > self.rank[py]:
			self.parent[py] = px
		elif self.rank[px] < self.rank[py]:
			self.parent[px] = py
		else:
			self.parent[py] = px
			self.rank[px] += 1
(N, K, P) = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
ans = []
uf = union_find(N)
Y = []
for i in range(N):
	Y.append((X[i], i))
Y.sort()
for i in range(N - 1):
	if Y[i + 1][0] - Y[i][0] <= K:
		uf.union(Y[i][1], Y[i + 1][1])
A = []
B = []
for i in range(P):
	(a, b) = [int(i) for i in input().split()]
	A.append(a - 1)
	B.append(b - 1)
for i in range(P):
	pa = uf.find(A[i])
	pb = uf.find(B[i])
	if pa == pb:
		ans.append('Yes')
	else:
		ans.append('No')
for i in ans:
	print(i)


(n, k, p) = map(int, input().split())
b = list(map(int, input().split()))
a = b[:]
a.sort()
dic = {}
dp = [i + 1 for i in range(n)]
for i in range(1, n):
	if a[i] - a[i - 1] <= k:
		dp[i] = dp[i - 1]
for i in range(n):
	dic[a[i]] = dp[i]
for _ in range(p):
	(x, y) = map(int, input().split())
	if dic[b[y - 1]] == dic[b[x - 1]]:
		print('Yes')
	else:
		print('No')


(n, k, p) = list(map(int, input().split()))
coor = list(map(int, input().split()))
forw = []
sort_coor = []
for (i, each) in enumerate(coor):
	sort_coor.append((each, i))
sort_coor.sort()
j = n - 2
msg = {}
max1 = sort_coor[n - 1][0] + k
msg[sort_coor[n - 1][1]] = max1
for i in range(n - 1, 0, -1):
	j = i - 1
	if sort_coor[i][0] - sort_coor[j][0] <= k:
		msg[sort_coor[j][1]] = max1
	else:
		max1 = sort_coor[j][0] + k
		msg[sort_coor[j][1]] = max1
for i in range(p):
	(a, b) = map(int, input().split())
	if msg[b - 1] == msg[a - 1]:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
from math import gcd, log2, log10, floor
import math
from collections import defaultdict, OrderedDict
from bisect import bisect_left
(n, k, p) = [int(i) for i in input().split()]
a = list(map(int, input().split()))
asort = a[:]
asort.sort()
dict = defaultdict(int)
theta = 1
dict[asort[0]] = 1
for i in range(1, n):
	if asort[i] - asort[i - 1] <= k:
		dict[asort[i]] = theta
	else:
		theta += 1
		dict[asort[i]] = theta
for i in range(p):
	(alpha, beta) = list(map(int, input().split()))
	alpha -= 1
	beta -= 1
	if dict[a[alpha]] == dict[a[beta]]:
		print('Yes')
	else:
		print('No')


def solve():
	(n, k, p) = map(int, input().split())
	arr = list(map(int, input().split()))
	new = []
	for i in range(n):
		new.append([arr[i], i])
	new1 = sorted(new, key=lambda x: x[0])
	po = 0
	store = [0] * n
	for i in range(1, n):
		if new1[i][0] - new1[i - 1][0] > k:
			po += 1
		store[new1[i][1]] = po
	for i in range(p):
		(p1, p2) = list(map(int, input().split()))
		if store[p1 - 1] == store[p2 - 1]:
			print('Yes')
		else:
			print('No')
solve()


from bisect import *
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = sorted(b)
d = []
k = t[0]
for i in range(a[0] - 1):
	if t[i + 1] - t[i] <= a[1]:
		k = t[i + 1]
	else:
		d.append(k + 1)
		k = t[i + 1]
d.append(k + 1)
for i in range(a[2]):
	c = list(map(int, input().split()))
	if c[0] - 1 <= a[0] and c[1] <= a[0]:
		if bisect(d, b[c[0] - 1]) == bisect(d, b[c[1] - 1]):
			print('Yes')
		else:
			print('No')
	else:
		print('No')


(n, k, p) = map(int, input().split())
arr = list(map(int, input().split()))[:n]
sort_arr = sorted(set(arr))
u = {sort_arr[0]: 0}
c = 0
for i in range(1, len(sort_arr)):
	if sort_arr[i - 1] + k < sort_arr[i]:
		c += 1
	u[sort_arr[i]] = c
for _ in range(0, p):
	(i, j) = map(int, input().split())
	a = arr[i - 1]
	b = arr[j - 1]
	if u[a] == u[b]:
		print('Yes')
	else:
		print('No')


(n, k, p) = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
arr = [[arr[i], i + 1] for i in range(n)]
arr = sorted(arr, key=lambda x: x[0])
d = dict()
for i in range(n):
	d[arr[i][1]] = i + 1
b = [0] * (n + 1)
for i in range(2, n + 1):
	if arr[i - 1][0] - arr[i - 2][0] <= k:
		b[i] = b[i - 1] + 1
for _ in range(p):
	(x, y) = list(map(int, input().strip().split()))
	x = d[x]
	y = d[y]
	if y < x:
		(x, y) = (y, x)
	if x >= y - b[y]:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
from collections import defaultdict, Counter
import math, heapq
input = stdin.readline
(n, k, p) = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
arr = [[arr[i], i + 1] for i in range(n)]
arr = sorted(arr, key=lambda x: x[0])
d = dict()
for i in range(n):
	d[arr[i][1]] = i
b = [0] * n
for i in range(1, n):
	if arr[i][0] - arr[i - 1][0] <= k:
		b[i] = b[i - 1] + 1
for _ in range(p):
	(x, y) = list(map(int, input().strip().split()))
	x = d[x]
	y = d[y]
	if y < x:
		(x, y) = (y, x)
	if x >= y - b[y]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
f = list(map(int, input().split()))
l = []
for i in range(n):
	l.append((f[i], i + 1))
l = sorted(l, key=lambda x: x[0])
d = {}
c = 1
d[l[0][1]] = 1
for i in range(1, n):
	if l[i][0] - l[i - 1][0] > k:
		c = c + 1
	d[l[i][1]] = c
for _ in range(p):
	(f1, f2) = map(int, input().split())
	if d[f1] == d[f2]:
		print('Yes')
	else:
		print('No')


(n, dis, q) = map(int, input().split())
arr = list(map(int, input().split()))
srt = sorted(arr)
curSet = 0
Dict = {srt[0]: curSet}
for i in range(1, len(srt)):
	if srt[i] - srt[i - 1] > dis:
		curSet += 1
	Dict[srt[i]] = curSet
for _ in range(q):
	(a, b) = map(int, input().split())
	(a, b) = (arr[a - 1], arr[b - 1])
	if Dict[a] == Dict[b]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
a.sort()
l = {a[0]: 0}
c = 0
for i in range(1, n):
	if a[i] - a[i - 1] <= k:
		l[a[i]] = c
	else:
		c += 1
		l[a[i]] = c
for i in range(p):
	(f1, f2) = map(int, input().split())
	if l[b[f1 - 1]] == l[b[f2 - 1]]:
		print('Yes')
	else:
		print('No')


(n, k, p) = map(int, input().split())
l = list(map(int, input().split()))
t_1 = []
for i in range(n):
	t_1.append([i, l[i]])
t_1 = sorted(t_1, key=lambda x: x[1], reverse=True)
dis = {}
for i in range(n):
	if i == 0:
		dis[i] = t_1[i][1] + k
		continue
	if t_1[i - 1][1] - t_1[i][1] <= k:
		dis[i] = dis[i - 1]
	else:
		dis[i] = t_1[i][1] + k
trans = {}
for i in range(n):
	trans[t_1[i][0]] = i
for i in range(p):
	(a, b) = map(int, input().split())
	t_2 = a - 1
	t_3 = b - 1
	if dis[trans[t_2]] == dis[trans[t_3]]:
		print('Yes')
	else:
		print('No')


import numpy as np
(N, K, P) = list(map(int, input().split()))
list_frogs = list(map(int, input().split()))
list_sorted = list_frogs.copy()
list_sorted.sort()
val = 0
dict_frogs = {list_sorted[0]: val}
for i in range(len(list_sorted) - 1):
	if list_sorted[i + 1] - list_sorted[i] > K:
		val += 1
		dict_frogs[list_sorted[i + 1]] = val
	else:
		dict_frogs[list_sorted[i + 1]] = val
for _ in range(P):
	(A, B) = list(map(int, input().split()))
	if dict_frogs[list_frogs[A - 1]] == dict_frogs[list_frogs[B - 1]]:
		print('Yes')
	else:
		print('No')


from collections import defaultdict

def solve(P, k):
	mp_index_value = defaultdict(int)
	for i in range(1, len(P) + 1):
		mp_index_value[i] = P[i - 1]
	P.sort()
	component = {P[0]: P[0]}
	value = P[0]
	for i in range(len(P) - 1):
		if abs(P[i] - P[i + 1]) <= k:
			component[P[i + 1]] = value
		else:
			value = P[i + 1]
			component[P[i + 1]] = P[i + 1]
	return (mp_index_value, component)
(n, k, p) = map(int, input().split())
P = list(map(int, input().split()))
(indexes, component) = solve(P, k)
for _ in range(p):
	(u, v) = map(int, input().split())
	u = indexes[u]
	v = indexes[v]
	if component[u] == component[v]:
		print('Yes')
	else:
		print('No')


def solve():
	(n, k, p) = list(map(int, input().split()))
	a = [[ind + 1, x] for (ind, x) in enumerate(list(map(int, input().split())))]
	a.sort(key=lambda x: x[1])
	d = {}
	for i in range(len(a)):
		if i == 0:
			d[a[0][0]] = 1
			continue
		if a[i][1] - a[i - 1][1] <= k:
			d[a[i][0]] = d[a[i - 1][0]]
		else:
			d[a[i][0]] = d[a[i - 1][0]] + 1
	for t in range(p):
		(x, y) = list(map(int, input().split()))
		if d[x] == d[y]:
			print('Yes')
		else:
			print('No')
solve()


from collections import defaultdict

def preCompute(arr, n, K):
	nonlocal maxDistance
	arr = list(enumerate(arr))
	arr.sort(key=lambda x: -x[1])
	maxDistance[arr[0][0]] = arr[0][1] + K
	for i in range(1, n):
		if arr[i - 1][1] - arr[i][1] <= K:
			maxDistance[arr[i][0]] = maxDistance[arr[i - 1][0]]
		else:
			maxDistance[arr[i][0]] = arr[i][1] + K

def answer(x, y):
	if maxDistance[x - 1] == maxDistance[y - 1]:
		return 'Yes'
	return 'No'
maxDistance = defaultdict(int)
(n, k, p) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
preCompute(arr, n, k)
for _ in range(p):
	(x, y) = map(int, input().strip().split())
	print(answer(x, y))


(n, k, p) = map(int, input().split())
list1 = list(map(int, input().split()))
list2 = sorted(list1.copy())
counts1 = {}
counts1[list2[0]] = 0
l = 0
for i in range(1, len(list2)):
	if list2[i] in counts1:
		continue
	if list2[i] - list2[i - 1] <= k:
		counts1[list2[i]] = l
	else:
		l += 1
		counts1[list2[i]] = l
for i in range(p):
	(a, b) = map(int, input().split())
	val1 = list1[a - 1]
	val2 = list1[b - 1]
	if counts1[val1] == counts1[val2]:
		print('Yes')
	else:
		print('No')


(N, K, P) = map(int, input().split())
As = list(map(int, input().split()))
Bs = [(x, i) for (i, x) in enumerate(As)]
Bs.sort()
i2j = {}
for (j, (A, i)) in enumerate(Bs):
	i2j[i] = j
max_reach = {}
max_reach[N - 1] = Bs[N - 1][0] + K
for j in range(N - 2, -1, -1):
	if Bs[j + 1][0] - Bs[j][0] <= K:
		max_reach[j] = max_reach[j + 1]
	else:
		max_reach[j] = Bs[j][0] + K
output = []
for _ in range(P):
	(i1, i2) = map(int, input().split())
	j1 = i2j[i1 - 1]
	j2 = i2j[i2 - 1]
	if max_reach[j1] == max_reach[j2]:
		output.append('Yes')
	else:
		output.append('No')
for o in output:
	print(o)


l = list(map(int, input().split()))
n = l[0]
k = l[1]
p = l[2]
s = []
frogs = list(map(int, input().split()))
s = [[frogs[i], i + 1] for i in range(n)]
s.sort()
m = [0] * (n + 1)
x1 = s[0][0]
w = 0
for i in range(len(s)):
	x2 = s[i][0]
	if x2 - x1 > k:
		w = w + 1
	m[s[i][1]] = w
	x1 = x2
while p:
	(a, b) = map(int, input().split())
	if m[a] == m[b]:
		print('Yes')
	else:
		print('No')
	p = p - 1


(useless, K, P) = list(map(int, input().split()))
A = [[ind + 1, x] for (ind, x) in enumerate(list(map(int, input().split())))]
key = {}
A.sort(key=lambda x: x[1])
group = 1
for i in range(len(A)):
	if i == 0:
		key[A[0][0]] = 1
		continue
	if A[i][1] - A[i - 1][1] <= K:
		key[A[i][0]] = key[A[i - 1][0]]
	else:
		key[A[i][0]] = key[A[i - 1][0]] + 1
for i in range(P):
	(a, b) = list(map(int, input().split()))
	if key[a] == key[b]:
		print('Yes')
	else:
		print('No')